<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/ScenePhase",
  "metadataVersion" : "0.1.0",
  "role" : "Enumeration",
  "symbol" : {
    "kind" : "Enumeration",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI10ScenePhaseO"
  },
  "title" : "ScenePhase"
}
-->

# ScenePhase

An indication of a scene’s operational state.

```
enum ScenePhase
```

## Overview

The system moves your app’s [`Scene`](/documentation/SwiftUI/Scene) instances through phases that reflect
a scene’s operational state. A scene’s operational state can vary
depending on what platform it’s on and whether it’s in the foreground,
minimized, in the app switcher, or in the background. You can perform
actions when the phase changes. Read the current phase by observing the
[`scenePhase`](/documentation/SwiftUI/EnvironmentValues/scenePhase) value in the [`Environment`](/documentation/SwiftUI/Environment):

```
@Environment(\.scenePhase) private var scenePhase
```

How you interpret the value depends on where it’s read from.
If you read the phase from inside a [`View`](/documentation/SwiftUI/View) instance, you obtain a value
that reflects the phase of the scene that contains the view. The following
example uses the [`onChange(of:initial:_:)`](/documentation/SwiftUI/View/onChange(of:initial:_:)-8wgw9) method to enable
a timer whenever the enclosing scene enters the [`ScenePhase.active`](/documentation/SwiftUI/ScenePhase/active) phase
and disable the timer when entering any other phase:

```
struct MyView: View {
    @ObservedObject var model: DataModel
    @Environment(\.scenePhase) private var scenePhase

    var body: some View {
        TimerView()
            .onChange(of: scenePhase) {
                model.isTimerRunning = (scenePhase == .active)
            }
    }
}
```

If you read the phase from within an [`App`](/documentation/SwiftUI/App) instance, you obtain an
aggregate value that reflects the phases of all the scenes in your app. The
app reports a value of [`ScenePhase.active`](/documentation/SwiftUI/ScenePhase/active) if any scene is active, or a
value of [`ScenePhase.inactive`](/documentation/SwiftUI/ScenePhase/inactive) when no scenes are active. This includes
multiple scene instances created from a single scene declaration; for
example, from a [`WindowGroup`](/documentation/SwiftUI/WindowGroup). When an app enters the
[`ScenePhase.background`](/documentation/SwiftUI/ScenePhase/background) phase, expect the app to terminate soon after.
You can use that opportunity to free any resources:

```
@main
struct MyApp: App {
    @Environment(\.scenePhase) private var scenePhase

    var body: some Scene {
        WindowGroup {
            MyRootView()
        }
        .onChange(of: scenePhase) {
            if scenePhase == .background {
                // Perform cleanup when all scenes within
                // MyApp go to the background.
            }
        }
    }
}
```

## Topics

### Getting scene phases

[`ScenePhase.active`](/documentation/SwiftUI/ScenePhase/active)

The scene is in the foreground and interactive.

[`ScenePhase.inactive`](/documentation/SwiftUI/ScenePhase/inactive)

The scene is in the foreground but should pause its work.

[`ScenePhase.background`](/documentation/SwiftUI/ScenePhase/background)

The scene isn’t currently visible in the UI.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)