CS4521:   Mobile and Topics in Web Programming

iOS App Lifecycle

 

 

First a diversion ---an app has a main.m that creates an instance of UIApplication

#import <UIKit/UIKit.h> 
  
int main(int argc, char *argv[]) 
{ 
    @autoreleasepool { 
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([MyAppDelegate class])); 
    } 
}

UIApplicationMain function will load the app’s main user interface file.

  • main interface file contains the initial view-related objects you plan to display in your app’s user interface.

  • Apps that “Using Storyboards”, this function loads the initial view controller from your storyboard and installs it in the window provided by your app delegate.

  • For apps that use nib files, the function loads the nib file contents into memory but does not install them in your app’s window; you must install them in the application:willFinishLaunchingWithOptions: method of your app delegate.

 

App Lifecycle

(see developer.apple.com for latest changes and details)

 

lifecycle

State

Description

Not running

The app has not been launched or was running but was terminated by the system.

Inactive

The app is running in the foreground but is currently not receiving events. (It may be executing other code though.) An app usually stays in this state only briefly as it transitions to a different state.

Active

The app is running in the foreground and is receiving events. This is the normal mode for foreground apps.

Background

The app is in the background and executing code. Most apps enter this state briefly on their way to being suspended. However, an app that requests extra execution time may remain in this state for a period of time. In addition, an app being launched directly into the background enters this state instead of the inactive state. For information about how to execute code while in the background, see “Background Execution and Multitasking.”

Suspended

The app is in the background but is not executing code. The system moves apps to this state automatically and does not notify them before doing so. While suspended, an app remains in memory but does not execute any code.

When a low-memory condition occurs, the system may purge suspended apps without notice to make more space for the foreground app.

 

Lifecycle Changes Call Following Methods in the App Delegate Object.

 

 

Launching the App --- a visualization

launch

 

 

 

Launching App in background ( when app runs in background mode like a service)---a visualization

>>same method applicationDidBecomeActive is called ---> what do you do???

    To determine whether your app is launching into the foreground or background, check the applicationState property of the shared UIApplication object in your application:willFinishLaunchingWithOptions: or application:didFinishLaunchingWithOptions: delegate method. When the app is launched into the foreground, this property contains the value UIApplicationStateInactive. When the app is launched into the background, the property contains the value UIApplicationStateBackground instead. You can use this difference to adjust the launch-time behavior of your delegate methods accordingly.

  • background app

 

© Lynne Grewe