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

1.4k views Asked by At

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???

2

There are 2 answers

5
Inder Kumar Rathore On BEST ANSWER
  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");
}


_____________________________

2
jaimeterrasa On

try to restore the "location warnings" in "settings->general->reset->reset location warnings". It worked for me using "startupdatinglocation".