15
iOS Application Lifecycle Insert a Picture Here Telerik Software Academy http://academy.telerik.com Mobile apps for iPhone & iPad

Telerik Software Academy Mobile apps for iPhone & iPad

Embed Size (px)

Citation preview

Page 1: Telerik Software Academy  Mobile apps for iPhone & iPad

iOS Application Lifecycle

Insert a Picture Here

Telerik Software Academyhttp://academy.telerik.com

Mobile apps for iPhone & iPad

Page 2: Telerik Software Academy  Mobile apps for iPhone & iPad

Table of Contents iOS app Execution model

UIApplication object

UIApplicationDelegate object

UIViewController Lifecycle

Events

State

2

Page 3: Telerik Software Academy  Mobile apps for iPhone & iPad

UIApplicationExecution model and lifecycle

Page 4: Telerik Software Academy  Mobile apps for iPhone & iPad

Execution model – Entry Point

iOS Application main function:

#import <UIKit/UIKit.h>#import "AppDelegate.h"

int main(int argc, char * argv[]){ @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); }}

4

Called in the main entry point to create the application object, delegate and set up the event

cycle

Page 5: Telerik Software Academy  Mobile apps for iPhone & iPad

UIApplicationDelegate

UIApplicationDelegate – protocol declares methods that are implemented by the delegate of the singleton UIApplication object.

AppDelegate – implements the application delegate to expose the control over the UIApplication

5

Page 6: Telerik Software Academy  Mobile apps for iPhone & iPad

UIApplication: States Application states:

Not Running – the app is not launched

Inactive – the app is running in the foreground but is currently not receiving events

Active – the app is running in the foreground but is receiving events

Background – the app is running in the background and executing code

Suspended – the app is in the background but is not executing code

6

Page 7: Telerik Software Academy  Mobile apps for iPhone & iPad

UIApplication: States (2)

7

Page 8: Telerik Software Academy  Mobile apps for iPhone & iPad

UIApplication – Launch Cycle

8

Page 9: Telerik Software Academy  Mobile apps for iPhone & iPad

UIViewController States

Overview and usage

Page 10: Telerik Software Academy  Mobile apps for iPhone & iPad

Overview: UIViewController

UIViewController: Provides the fundamental view-

management model

Coordinates its efforts with model objects and other controller objects communication

Responsible for a single view

States preservation and restoration

10

Page 11: Telerik Software Academy  Mobile apps for iPhone & iPad

UIViewController – API (1)

Managing the View view – the root view of the

controller’s view hierarchy

viewDidLoad – it is called after the view controller has loaded its view hierarchy into memory

Handling Memory Warning didReceiveMemoryWarning

Sent to the view controller when the app receives a memory warning

11

Page 12: Telerik Software Academy  Mobile apps for iPhone & iPad

UIViewController – API (2)

Responding to View Events viewWillAppear

Notifies that its view to be added to a view hierarchy

viewDidAppear Notifies that that its view is added to

a view hierarchy

viewWillDisappear Notifies that its view is about to be

removed from a view hierarchy12

Page 13: Telerik Software Academy  Mobile apps for iPhone & iPad

UIViewController – API (3)

viewDidDisappear Notifies that its view is about to be

removed from a view hierarchy

viewWillLayoutSubviews Called to notify the view controller

that its view is about to layout its subviews

viewDidLayoutSubviews Called to notify the view controller

that its view has just laid out its subviews 13

Page 14: Telerik Software Academy  Mobile apps for iPhone & iPad

UIViewController - Lifecycle

14

Page 15: Telerik Software Academy  Mobile apps for iPhone & iPad

Questions?

iOS Application Lifecycle