ioslocationxcode4.2cllocationmanagerfast-app-switching

Grey GPS arrow shown in statusbar although location based application killed using Fast App Switcher


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:


Solution

    1. Significant Location updates are available if you app is not in foreground.
    2. I just give you an idea I have done something like this but I don't know what happens in your case.
      Just register your app for background task and do some thing for testing purpose in that case if you kill your app via fast app switching then the delegate method 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");
    }
    


    _____________________________