What to do when the IOS app starts

Source: Internet
Author: User

When your application launches (either in the foreground or in the background), use your application delegate application:willFinishLaunchingWithOptions: and the application:didFinishLaunchingWithOptions: method to perform the following actions:

    • Check the contents of the Startup options dictionary for the reasons for starting the application and respond accordingly.

    • Initialize the key data structures for your application.

    • Prepare your application's Windows and views for display:

At startup, the system will automatically load your application's main storyboard to load the initial view controller.

application:willFinishLaunchingWithOptions:And the application:didFinishLaunchingWithOptions: method should always be as lightweight as possible to reduce the startup time of your application. The application is expected to start, initialize the UIWindow, and start processing events in less than 5 seconds. If the application does not complete its startup cycle in time, the system kills it and cannot respond. Therefore, any task that may slow down the startup speed, such as access to the network, should be scheduled to execute on the worker thread.

When your application starts, it transfers the never-running state to the active or background state and transitions briefly in the inactive state. as part of the startup cycle, the system creates a process and main thread for your application and main invokes the functionality of your application on that main thread . main The default function that comes with the Xcode project immediately transfers control to the Uikit framework, and the Uikit framework finishes initializing the application and is ready to run most of the work

Shows the sequence of events that occurred when the application was launched to the foreground, including the application delegate method that was invoked.

When your application launches into the background (typically to handle some kind of background event), the boot cycle changes slightly to the state shown . The main difference is that your app is not active, but instead goes into the background state to handle the event and may pause at some point after that. When you boot into the background, the app's user interface file is still loaded, but the app's window does not appear.

to determine if your application is booting to the foreground or the background, in your or in the delegate method Check applicationState shared UIApplication The properties of the object . This property contains the value when the application launches to the foreground . This property will contain the value when the application is launched into the background . You can use this difference to adjust the start-time behavior of the delegate method accordingly.

application:willFinishLaunchingWithOptions:

application:didFinishLaunchingWithOptions:

UIApplicationStateInactive

UIApplicationStateBackground

coping with temporary interruptions

When an alert-based interrupt occurs (for example, a call), the application is temporarily moved to an inactive state so that the system can prompt the user. The application stays in this state until the user dismisses the alert. At this point, the application returns to the active state or to the background state.
Shows the flow of events that occur through your application when an alert-based interrupt occurs.

What to do when your application enters the foreground

back to the foreground, your application has the opportunity to restart the task that stopped when it moved to the background. The steps that appear when you move to the foreground are shown in step 4-4 . the applicationWillEnterForeground: method should undo applicationDidEnterBackground: Any action done in your method , and the applicationDidBecomeActive: method should continue to perform the same activation task as when it was started.

The above check with Apple Official document, original address:

https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/ Strategiesforhandlingappstatetransitions/strategiesforhandlingappstatetransitions.html#//apple_ref/doc/uid/ Tp40007072-ch8-sw2

What to do when the IOS app starts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.