<!--
{
  "documentType" : "article",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/preparing-your-ui-to-run-in-the-foreground",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Preparing your UI to run in the foreground"
}
-->

# Preparing your UI to run in the foreground

Configure your app to appear onscreen.

## Discussion

Use foreground transitions to prepare your app’s UI to appear onscreen. An app’s transition to the foreground is usually in response to a user action. For example, when the user taps the app’s icon, the system launches the app and brings it to the foreground. Use a foreground transition to update your app’s UI, acquire resources, and start the services you need to handle user requests.

All state transitions result in UIKit sending notifications to the appropriate delegate object:

- In iOS 13 and later — A [`UISceneDelegate`](/documentation/UIKit/UISceneDelegate) object.
- In iOS 12 and earlier — The [`UIApplicationDelegate`](/documentation/UIKit/UIApplicationDelegate) object.

You can support both types of delegate objects, but UIKit always uses scene delegate objects when they’re available. UIKit notifies only the scene delegate associated with the specific scene that’s entering the foreground. For information about how to configure scene support, see [Specifying the scenes your app supports](/documentation/UIKit/specifying-the-scenes-your-app-supports).

### Update your app’s data model when entering the foreground

At launch time, the system starts your app in the inactive state before transitioning it to the foreground. Use your app’s launch-time methods to perform any work needed at that time. For an app that’s in the background, UIKit moves your app to the inactive state by calling one of the following methods:

- For apps that support scenes — The [`sceneWillEnterForeground(_:)`](/documentation/UIKit/UISceneDelegate/sceneWillEnterForeground(_:)) method of the appropriate scene delegate object.
- For all other apps — The [`applicationWillEnterForeground(_:)`](/documentation/UIKit/UIApplicationDelegate/applicationWillEnterForeground(_:)) method.

When transitioning from the background to the foreground, use these methods to load resources from disk and fetch data from the network.

For information about how to prepare your app at launch time, see [Responding to the launch of your app](/documentation/UIKit/responding-to-the-launch-of-your-app).

### Configure your user interface and initial tasks at activation

The system moves your app to the active state immediately before displaying the app’s UI. Activation is a good time to configure your app’s UI and runtime behavior; specifically:

- Show your app’s windows, if needed.
- Change the currently visible view controller, if needed.
- Update the data values and state of views and controls.
- Display controls to resume a paused game.
- Start or resume any dispatch queues that you use to execute tasks.
- Update data source objects.
- Start timers for periodic tasks.

Put your configuration code in one of the following methods:

- For a scene-based UI — The [`sceneDidBecomeActive(_:)`](/documentation/UIKit/UISceneDelegate/sceneDidBecomeActive(_:)) method of the appropriate scene delegate object.
- For all other apps — The [`applicationDidBecomeActive(_:)`](/documentation/UIKit/UIApplicationDelegate/applicationDidBecomeActive(_:)) method of your app delegate object.

Activation is also the time to put finishing touches on your UI before displaying it to the user. Don’t run any code that might block your activation method. Instead, make sure you have everything you need in advance. For example, if your data changes frequently outside of the app, use background tasks to fetch updates from the network before your app returns to the foreground. Otherwise, be prepared to display existing data while you fetch changes asynchronously.

### Start UI-specific tasks when your view appears

When your activation method returns, UIKit shows any windows that you made visible. It also notifies any relevant view controllers that their views are about to appear. Use your view controller’s [`viewWillAppear(_:)`](/documentation/UIKit/UIViewController/viewWillAppear(_:)) method to perform any final updates to your interface. For example:

- Start user interface animations, as appropriate.
- Begin playing media files, if auto-play is enabled.
- Begin displaying graphics for games and immersive content at their full frame rates.

Don’t try to show a different view controller or make major changes to your user interface. By the time your view controller appears onscreen, your interface should be ready to display.

## Topics

### State-change notifications

[Processing queued notifications](/documentation/UIKit/processing-queued-notifications)

Respond to notifications when coming out of the suspended state.



---

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)