Handling Interruptions
There are two occasions when your application might need to give up focus. The first is when a dialog overlay is triggered externally, such as with an incoming SMS message or phone call. The second is when your application is running but the user clicks the lock button or the phone triggers its autolock mechanism in response to a lack of user input.
The most important thing for application developers to remember when considering interruptions is that, because your application is being interrupted somehow, a user may take an action that causes the termination of your application. A good example is when a phone call comes in and triggers the familiar “answer or ignore” dialog. If the user ignores the call, your application will regain focus. If the user answers the phone, your application will go into a suspended state.
The UIApplicationDelegate
protocol that
defines an application delegate includes three methods that handle
interruptions:
The
applicationWillResignActive:
method is called when the OS decides to shift your application out of the primary focus. Any time this method is invoked, you might want to look for operations that can be paused to reflect the lower (visual) priority state of your application. For example, if you are doing heavy graphics processing for display, or using resource-hungry features such as the accelerometer for user input, you can likely pause those operations.The method
applicationDidBecomeActive:
is called when your application ...
Get Programming the iPhone User Experience now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.