System Alerts Calling Methods
System alerts, such as “Low battery, 20% of battery remaining” will call the following methods:
applicationWillResignActive called before the alert comes up
applicationDidBecomeActive called after the alert is dismissed
A typical problem is if you use applicationDidBecomeActive to detect your app starting up from a suspended state (from multitasking). To solve this use applicationWillEnterForeground (which isn’t called after a system alert), or if you need a ‘did’ rather than a ‘will’ method then you can use this approach:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
ThisIsAppStartup = YES;
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
ThisIsAppStartup = YES;
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
if (ThisIsAppStartup) //Don't do if we're just returning from a system alert like low battery
{
//We are here after didFinishLaunchingWithOptions and applicationWillEnterForeground
ThisIsAppStartup = NO;
...
}
}