You’re closer than you think to a career in tech. Our grads have launched rewarding new careers — you can too.View Our Jobs Report
For my first ever blog post, I think discussing App Delegates is extremely useful in iOS dev. The App Delegate is instrumental in every iOS app. It’s methods are called every time you launch an app, switch applications or get a phone call, or come back to an app you opened.
When you begin a project (even an Empty Project), Xcode prefills the most commonly used methods, and even includes commented descriptions as to when each one is called. Below is a screenshot of the different methods and their descriptions.
When your apps becomes more complicated in size and features, the order in which your App Delegate calls its methods becomes extremely important. It’s especially interesting to understand when these methods are called in relation to the when awake To better understand the order, I created a project with an NSLog in each App Delegate method and in my Root View Controller’s awakeFromNib, viewDidLoad, viewWillAppear, and viewDidAppear methods.
Below are my results in the most common scenarios:
Application’s Fresh Launch:
2013-10-13 12:24:09.941 AppDelegate Root View Controller: Awake From Nib
2013-10-13 12:24:09.948 AppDelegate App Delegate: didFinishLaunchingWithOptions
2013-10-13 12:24:09.954 AppDelegate Root View Controller: View Did Load
2013-10-13 12:24:09.956 AppDelegate Root View Controller: View Will Appear
2013-10-13 12:24:09.968 AppDelegate App Delegate: applicationDidBecomeActive
2013-10-13 12:24:09.974 AppDelegate Root View Controller: View Did Appear
Pushed Home Button From Application:
2013-10-13 12:25:57.286 AppDelegate App Delegate: applicationWillResignActive
2013-10-13 12:25:57.287 AppDelegate App Delegate: applicationDidEnterBackground
Tapped on Application’s Icon to start it from the background:
2013-10-13 12:26:32.779 AppDelegate App Delegate: applicationWillEnterForeground
2013-10-13 12:26:32.784 AppDelegate App Delegate: applicationDidBecomeActive
Received a Phone Call / Received a Text Notification/ Swiped Down to Open Notification Center / Swiped Up to Open Control Center:
2013-10-13 12:28:10.952 AppDelegate App Delegate: applicationWillResignActive
Answered Phone Call:
2013-10-13 12:28:17.511 AppDelegate App Delegate: applicationDidEnterBackground
Clicked View on Text Notification Alert:
2013-10-13 12:33:39.876 AppDelegate App Delegate: applicationDidBecomeActive
2013-10-13 12:33:40.480 AppDelegate App Delegate: applicationWillResignActive
2013-10-13 12:33:40.488 AppDelegate App Delegate: applicationDidEnterBackground
Declined Phone Call / Clicked Close on Text Notification Alert / Swiped Up to Close Notification Center / Swiped Down to Close Control Center:
2013-10-13 12:30:07.440 AppDelegate App Delegate: applicationDidBecomeActive
Those are probably the most common App Delegate methods most apps need to handle. Make sure you handle them when you are creating apps for the App Store. That’s all for now. I’ll be back soon!
Blog Post Author
Since we opened our doors in 2012, thousands of students have joined Flatiron School to launch new careers in tech.
Find the perfect course for you across our in-person and online programs designed to power your career change.
Connect with students and staff at meetups, lectures, and demos – on campus and online.
Have a question about our programs? Our admissions team is here to help.