Effective ways of handling Interruptions in iPhone App Development
August 18th, 2009 by Ravi Korukonda Leave a reply »It is a known and acknowledged fact that user’s experience with your iPhone app is of paramount importance in keeping them glued to it. Towards that, handling interruptions gracefully in an iPhone app plays a key role.
iPhone being a “one app at a time” device, apps get interrupted by incoming Phone Calls, SMSs, Calendar Events, Alarms or Push Notifications from other apps on the device.
The iPhone SDK provides a few methods in UIApplicationDelegate which can be implemented to handle the interruptions and keep user’s experience as flawless/seamless as possible.
The Interruption
- (void)applictaionWillResignActive:(UIApplication*)application
This method lets your application know that it is about to be interrupted by the iPhone OS. The name of the method suggests that your app will no longer be active, and will not respond to any user actions until the interruption is taken care of. An interruption like an incoming phone call or an SMS can either be accepted or dismissed by the user, and this is where you have to perform all tasks necessary to resume if the user chooses to leave the application. If the app was a game, it could save any game state needed for a resumption later.
The Resumption / Interruption Dismissed
- (void)applicationDidBecomeActive:(UIApplication*)application
When your application is about to become active again, this method is called by the iPhone OS. If the user decides not to leave the application and dismisses the interruption this is a good place to allow the user resume using the application. Since the application has not yet been closed, all the required state to resume is still in memory and continuing using the app is really as simple as a Pause/Resume feature.
The Interruption Accepted
- (void)applicationWillTerminate:(UIApplication*)application
If the user decides to leave the application or accepts an interruption, this method call from the iPhone OS notifies us of that intention. This is the place where you save all necessary state of the app/game to resume later.
The best place to save all game/app state to resume later is “applicationWillResignActive”. The simple reason being, all iPhone interruptions need user’s input to either accept or dismiss the interruption. This action from the user might needs a few seconds of his/her time to understand what the interruption is and what to do with it. This duration should be just enough for a well written application to save all state. Whereas, in the case of the application being closed by the user, iPhone OS wouldn’t wait for the app to complete saving state. The time available is really short and many applications might fail to save state.
Since there are multiple reasons and ways for an app being closed, state saving method calls need to be placed both in “applictaionWillResignActive” and “applictaionWillTerminate”. But ensure you don’t waste precious time in saving app state at both places. If the user closes the application by pressing the “Home” button, use “applictaionWillTerminate” to save state and necessary cleanups. If the application is being closed due to an interruption, save state in “applictaionWillResignActive” and perform any necessary cleanup in “applictaionWillTerminate”.
So, make it a point to use various UIApplicationDelegate methods to maintain user experience and reusability of the app. Keep your users glued to your application or game and return to it after an interruption.
For more tips and strategies on iPhone App Development, click here. For iPhone app marketing tips, try this link.
Awesome tips!!
thanks for the tips ..however, it would be helpful if you can provide an iphone app sample code for saving and restoring an app. as i am new to iphone app development, i do not have an idea how to save the state of my application. kindly help me out!
Awesome find!
Very nice site!
Thankyou, I didn’t knew this, thanks.
Thank you for your information. Much appreciated. You mostly need to search through tons of rubbish to find a little decent information! Anybody know the very best site to pick up free things inside the Uk?
I think this is wonderful I truly appreciate the informations shared in this post I am going to bookmark this!