I am writing a location based application for iOS 5. The application is using the CLLocationManager
to receive Location updates.
When the application is started I am creating the LocationManager, calling [self.locationManager startUpdatingLocation];
and the grey location arrow appears in the statusbar.
When the application enters background I am calling
[self.locationManager stopUpdatingLocation];
[self.locationManager startMonitoringSignificantLocationChanges];
cause I just want to receive significant location changes while the app is in background. The grey location arrow is still shown.
I also have an exit button in my application where I am calling
[self.locationManager stopUpdatingLocation];
exit(0);
When the user presses the Exit-Button the application finishes and the grey location button disappears from the statusbar. Everythings fine until now.
A problem appears, when the users finishes the application using the Fast App Switcher, because afterwards the grey location arrow is still shown in the status bar, although the application isn't running. The grey location arrow first disappears, when the user removes the application from his iPhone.
So the questions are:
When the users finishes the application using Fast App Switcher and the grey arrow is still shown in the status bar, does this mean, that location updates are still executed or does this mean, that an application used Location services whithin the last 24 hours? I guess the answer is the first one, location updates are still executed!
The application needs to be executed in background, so I can't stop the LocationManager when the application enters background. applicationWillTerminate:
gets never called when the user kills the application using Fast App Switcher. Is there any way to receive an event, when the application is terminated using Fast App Switcher or is terminated by the the OS????
I've seen some other applications, where the grey arrow in the status bar disappears when the application is killed using Fast App Switcher. How does these applications achieve this???
applicationWillTerminate:
is always called.
___________Edited______________
just add this varibale into your AppDelegate.h
UIBackgroundTaskIdentifier bgTask;
and make your delegate method like this and now kill your app
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIApplication *app = [UIApplication sharedApplication];
if ([app respondsToSelector:@selector(beginBackgroundTaskWithExpirationHandler:)]) {
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
// Synchronize the cleanup call on the main thread in case
// the task actually finishes at around the same time.
dispatch_async(dispatch_get_main_queue(), ^{
if (bgTask != UIBackgroundTaskInvalid)
{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}
});
}];
}
}
- (void)applicationWillTerminate:(UIApplication *)application
{
NSLog(@"is terminated");
}
_____________________________