App anatomy and life cycle

SV.CO
SV.COOnline Learning Platform um SV.CO
Unit 4—Lesson 2:
App Anatomy and Life Cycle
App life cycle
Not running
Inactive
Active
Background
Suspended
Foreground
Background
Break down the delegate
Did Finish Launching

Will Resign Active

Did Enter Background

Will Enter Foreground

Did Become Active

Will Terminate
Did Finish Launching
UIApplicationDelegate protocol methods
App has finished launching

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:
[UIApplicationLaunchOptionsKey: Any]?) -> Bool {
return true
}
Override point for customization after app launch
Will Resign Active
UIApplicationDelegate protocol methods
App is about to move from active to inactive state

func applicationWillResignActive(_ application: UIApplication) {
}
Can occur for certain types of temporary interruptions (such as an incoming phone
call or SMS message)

Can occur when the user quits the app and it begins the transition to the 

background state

Use to pause ongoing tasks, disable timers, and invalidate graphics rendering
callbacks
Did Enter Background
UIApplicationDelegate protocol methods
App is about to move from active to inactive state

func applicationDidEnterBackground(_ application: UIApplication) {
}
Use to release shared resources, save user data, invalidate timers, and store
enough application state information to restore your application to its current state
in case it’s terminated later

If your application supports background execution, this method is called instead
of applicationWillTerminate: when the user quits
Will Enter Foreground
UIApplicationDelegate protocol methods
Called immediately before the applicationDidBecomeActive function

func applicationWillEnterForeground(_ application: UIApplication) {
}
Called as part of transition from the background to the active state

Can be used to undo many of the changes made on entering the background
Did Become Active
UIApplicationDelegate protocol methods
App was launched by the user or system

func applicationDidBecomeActive(_ application: UIApplication) {
}
Restart any tasks that were paused (or not yet started) while the app was inactive

If the app was previously in the background, optionally refresh the user interface
Will Terminate
UIApplicationDelegate protocol methods
App is about to be terminated

func applicationWillTerminate(_ application: UIApplication) {
}
Save data if appropriate

See also applicationDidEnterBackground:
Which methods should I use?
Start with the methods that will run when launching, reopening, or closing 

your app

• applicationDidFinishLaunchingWithOptions
• applicationWillResignActive
• applicationDidBecomeActive
Take advantage of the other three delegate methods as you become more experienced
App Anatomy and Life Cycle
Unit 4—Lesson 2
Learn more about the different life cycle states and the delegate hooks for
executing logic as the app moves through each state.
Lab: App Event Count
Unit 4—Lesson 2
Create an app that provides a visual representation of the app life cycle. 

Your app will update labels on the view when different delegate methods are called.
© 2017 Apple Inc. 

This work is licensed by Apple Inc. under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license.
1 von 13

Más contenido relacionado

Similar a App anatomy and life cycle(20)

Mad textbook 63-116Mad textbook 63-116
Mad textbook 63-116
PrathishGM71 views
Bcsf13a019_mcqs_eadBcsf13a019_mcqs_ead
Bcsf13a019_mcqs_ead
MarYam IqBal111 views
iOS app dev Training - Session1iOS app dev Training - Session1
iOS app dev Training - Session1
Hussain Behestee729 views
android activityandroid activity
android activity
Deepa Rani3.2K views
Android application developmentAndroid application development
Android application development
Md. Mujahid Islam206 views
AndroidAndroid
Android
Natasha Ramírez446 views
Compose Camp by GDSC NSUTCompose Camp by GDSC NSUT
Compose Camp by GDSC NSUT
MOHITCHAURASIYA648 views
Lab3-AndroidLab3-Android
Lab3-Android
Lilia Sfaxi587 views
Dive into Angular, part 5: ExperienceDive into Angular, part 5: Experience
Dive into Angular, part 5: Experience
Oleksii Prohonnyi288 views
fragments-activity.pptxfragments-activity.pptx
fragments-activity.pptx
SriKGangadharRaoAssi4 views
Windows phone 8 session 9Windows phone 8 session 9
Windows phone 8 session 9
hitesh chothani323 views
User Forms & API integrationUser Forms & API integration
User Forms & API integration
Knoldus Inc.129 views
Unit2Unit2
Unit2
DevaKumari Vijay65 views
ActivityActivity
Activity
roopa_slide529 views

Más de SV.CO

Handout   level-1-module-1Handout   level-1-module-1
Handout level-1-module-1SV.CO
320 views20 Folien
Persistence And DocumentsPersistence And Documents
Persistence And DocumentsSV.CO
816 views59 Folien
Saving DataSaving Data
Saving DataSV.CO
220 views17 Folien
Alerts notificationAlerts notification
Alerts notificationSV.CO
256 views52 Folien

Más de SV.CO(20)

Handout   level-1-module-1Handout   level-1-module-1
Handout level-1-module-1
SV.CO320 views
Persistence And DocumentsPersistence And Documents
Persistence And Documents
SV.CO816 views
Saving DataSaving Data
Saving Data
SV.CO220 views
Alerts notificationAlerts notification
Alerts notification
SV.CO256 views
UI DynamicsUI Dynamics
UI Dynamics
SV.CO190 views
Practical animationPractical animation
Practical animation
SV.CO266 views
Camera And EmailCamera And Email
Camera And Email
SV.CO198 views
Scroll viewsScroll views
Scroll views
SV.CO184 views
Intermediate table viewsIntermediate table views
Intermediate table views
SV.CO154 views
Table viewsTable views
Table views
SV.CO146 views
ClosuresClosures
Closures
SV.CO124 views
ProtocolsProtocols
Protocols
SV.CO140 views
ExtensionsExtensions
Extensions
SV.CO134 views
GesturesGestures
Gestures
SV.CO177 views
Controls in actionControls in action
Controls in action
SV.CO105 views

Último(20)

App anatomy and life cycle

  • 1. Unit 4—Lesson 2: App Anatomy and Life Cycle
  • 2. App life cycle Not running Inactive Active Background Suspended Foreground Background
  • 3. Break down the delegate Did Finish Launching Will Resign Active Did Enter Background Will Enter Foreground Did Become Active Will Terminate
  • 4. Did Finish Launching UIApplicationDelegate protocol methods App has finished launching func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { return true } Override point for customization after app launch
  • 5. Will Resign Active UIApplicationDelegate protocol methods App is about to move from active to inactive state func applicationWillResignActive(_ application: UIApplication) { } Can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) Can occur when the user quits the app and it begins the transition to the 
 background state Use to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks
  • 6. Did Enter Background UIApplicationDelegate protocol methods App is about to move from active to inactive state func applicationDidEnterBackground(_ application: UIApplication) { } Use to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it’s terminated later If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits
  • 7. Will Enter Foreground UIApplicationDelegate protocol methods Called immediately before the applicationDidBecomeActive function func applicationWillEnterForeground(_ application: UIApplication) { } Called as part of transition from the background to the active state Can be used to undo many of the changes made on entering the background
  • 8. Did Become Active UIApplicationDelegate protocol methods App was launched by the user or system func applicationDidBecomeActive(_ application: UIApplication) { } Restart any tasks that were paused (or not yet started) while the app was inactive If the app was previously in the background, optionally refresh the user interface
  • 9. Will Terminate UIApplicationDelegate protocol methods App is about to be terminated func applicationWillTerminate(_ application: UIApplication) { } Save data if appropriate See also applicationDidEnterBackground:
  • 10. Which methods should I use? Start with the methods that will run when launching, reopening, or closing 
 your app • applicationDidFinishLaunchingWithOptions • applicationWillResignActive • applicationDidBecomeActive Take advantage of the other three delegate methods as you become more experienced
  • 11. App Anatomy and Life Cycle Unit 4—Lesson 2 Learn more about the different life cycle states and the delegate hooks for executing logic as the app moves through each state.
  • 12. Lab: App Event Count Unit 4—Lesson 2 Create an app that provides a visual representation of the app life cycle. Your app will update labels on the view when different delegate methods are called.
  • 13. © 2017 Apple Inc. This work is licensed by Apple Inc. under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license.