Instance Method

application(_:willFinishLaunchingWithOptions:)

Tells the delegate that the launch process has begun but that state restoration has not yet occurred.

Declaration

optional func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool

Parameters

application

Your singleton app object.

launchOptions

A dictionary indicating the reason the app was launched (if any). The contents of this dictionary may be empty in situations where the user launched the app directly. For information about the possible keys in this dictionary and how to handle them, see Launch Options Keys.

Return Value

false if the app cannot handle the URL resource or continue a user activity, or if the app should not perform the application(_:performActionFor:completionHandler:) method because you’re handling the invocation of a Home screen quick action in this method; otherwise return true. The return value is ignored if the app is launched as a result of a remote notification.

Discussion

Use this method (and the corresponding application(_:didFinishLaunchingWithOptions:) method) to initialize your app and prepare it to run. This method is called after your app has been launched and its main storyboard or nib file has been loaded, but before your app’s state has been restored. At the time this method is called, your app is in the inactive state.

If your app was launched by the system for a specific reason, the launchOptions dictionary contains data indicating the reason for the launch. For some launch reasons, the system may call additional methods of your app delegate. For example, if your app was launched to open a URL, the system calls the application(_:open:options:) method after your app finishes initializing itself. The presence of the launch keys gives you the opportunity to plan for that behavior. In the case of a URL to open, you might want to prevent state restoration if the URL represents a document that the user wanted to open.

When asked to open a URL, the return result from this method is combined with the return result from the application(_:didFinishLaunchingWithOptions:) method to determine if a URL should be handled. If either method returns false, the system does not call the application(_:open:options:) method. If you do not implement one of the methods, only the return value of the implemented method is considered.

In some cases, the user launches your app with a Home screen quick action. To ensure you handle this launch case correctly, read the discussion in the application(_:performActionFor:completionHandler:) method.

See Also

Responding to App State Changes and System Events

func application(UIApplication, didFinishLaunchingWithOptions: [UIApplicationLaunchOptionsKey : Any]? = nil)

Tells the delegate that the launch process is almost done and the app is almost ready to run.

func applicationDidFinishLaunching(UIApplication)

Tells the delegate when the app has finished launching. Don’t use. Instead, use application(_:didFinishLaunchingWithOptions:).

func applicationDidBecomeActive(UIApplication)

Tells the delegate that the app has become active.

func applicationWillResignActive(UIApplication)

Tells the delegate that the app is about to become inactive.

func applicationDidEnterBackground(UIApplication)

Tells the delegate that the app is now in the background.

func applicationWillEnterForeground(UIApplication)

Tells the delegate that the app is about to enter the foreground.

func applicationWillTerminate(UIApplication)

Tells the delegate when the app is about to terminate.

func applicationProtectedDataWillBecomeUnavailable(UIApplication)

Tells the delegate that the protected files are about to become unavailable.

func applicationProtectedDataDidBecomeAvailable(UIApplication)

Tells the delegate that protected files are available now.

func applicationDidReceiveMemoryWarning(UIApplication)

Tells the delegate when the app receives a memory warning from the system.

func applicationSignificantTimeChange(UIApplication)

Tells the delegate when there is a significant change in the time.