SlideShare a Scribd company logo
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.

More Related Content

PDF
fastcollab - open source applicant tracking software
PPTX
watch_kit_v_1.0
PDF
Workflow automation i phone application for a construction company
PDF
Iphone app programming guide
PPTX
iOS app dev Training - Session1
PPTX
iOS Development (Part 2)
KEY
iOS4 multitasking development notes
KEY
Local Notifications @ Melbourne Cocoaheads (Aug 10)
fastcollab - open source applicant tracking software
watch_kit_v_1.0
Workflow automation i phone application for a construction company
Iphone app programming guide
iOS app dev Training - Session1
iOS Development (Part 2)
iOS4 multitasking development notes
Local Notifications @ Melbourne Cocoaheads (Aug 10)

Similar to App anatomy and life cycle (20)

PPTX
iOS Beginners Lesson 2
PDF
Declarative presentations UIKonf
PPTX
Cross platform mobile development in c#
PPTX
Affordable iPhone Mobile Apps Development Services
PDF
Mad textbook 63-116
PPTX
Basic iOS Training with SWIFT - Part 1
PDF
03 objective-c session 3
PPTX
Presentation3 actionsheet alertview
PDF
Bcsf13a019_mcqs_ead
PDF
Iphone course 3
PDF
Introduction of Xcode
PDF
Dev101
PDF
View controller life cycle
PDF
04 Model View Controller
KEY
漫游iOS开发指南
PDF
Apple iPhone App Programming Guide
PDF
iPhone dev intro
PDF
Beginning to iPhone development
PDF
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
PPTX
iOS for C# Developers - DevConnections Talk
iOS Beginners Lesson 2
Declarative presentations UIKonf
Cross platform mobile development in c#
Affordable iPhone Mobile Apps Development Services
Mad textbook 63-116
Basic iOS Training with SWIFT - Part 1
03 objective-c session 3
Presentation3 actionsheet alertview
Bcsf13a019_mcqs_ead
Iphone course 3
Introduction of Xcode
Dev101
View controller life cycle
04 Model View Controller
漫游iOS开发指南
Apple iPhone App Programming Guide
iPhone dev intro
Beginning to iPhone development
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
iOS for C# Developers - DevConnections Talk
Ad

More from SV.CO (20)

PDF
Handout level-1-module-1
PDF
Persistence And Documents
PDF
Building complex input screens
PDF
Working with the Web: 
Decoding JSON
PDF
Saving Data
PDF
Alerts notification
PDF
UI Dynamics
PDF
Practical animation
PDF
Segues and navigation controllers
PDF
Camera And Email
PDF
Scroll views
PDF
Intermediate table views
PDF
Table views
PDF
Closures
PDF
Protocols
PDF
Extensions
PDF
Gestures
PDF
Controls in action
PDF
Auto layout and stack views
PDF
Custom view
Handout level-1-module-1
Persistence And Documents
Building complex input screens
Working with the Web: 
Decoding JSON
Saving Data
Alerts notification
UI Dynamics
Practical animation
Segues and navigation controllers
Camera And Email
Scroll views
Intermediate table views
Table views
Closures
Protocols
Extensions
Gestures
Controls in action
Auto layout and stack views
Custom view
Ad

Recently uploaded (20)

PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Insiders guide to clinical Medicine.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Institutional Correction lecture only . . .
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Classroom Observation Tools for Teachers
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
Final Presentation General Medicine 03-08-2024.pptx
Insiders guide to clinical Medicine.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Institutional Correction lecture only . . .
human mycosis Human fungal infections are called human mycosis..pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
TR - Agricultural Crops Production NC III.pdf
Classroom Observation Tools for Teachers
Abdominal Access Techniques with Prof. Dr. R K Mishra
O5-L3 Freight Transport Ops (International) V1.pdf
RMMM.pdf make it easy to upload and study
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
2.FourierTransform-ShortQuestionswithAnswers.pdf
Microbial disease of the cardiovascular and lymphatic systems
01-Introduction-to-Information-Management.pdf
Week 4 Term 3 Study Techniques revisited.pptx

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.