3

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

android
  • 247
  • 1
  • 3
  • 12

2 Answers2

3

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

  • same for me - my issue was that my App never seemed to stop updating, it would show a purple arrow after killing all processes using the Multitasking Bar. After resetting location services warnings, everything works as expected - the location indicator disappears after ~7 seconds after backgrounding the App – Henrik Hartz Aug 27 '12 at 09:33
  • I realize this is an old answer but nonetheless, be aware that one of the reasons this may seem like it works (at least for new iOS versions) is that it turns off the status bar icon completely for all apps. So after resetting, make sure to go back into `Settings` -> `Privacy` -> `Location Services` -> `System Services` -> then at the bottom turn the `Status Bar Icon` setting back on. – hvaughan3 Apr 22 '16 at 13:11
3
  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");
}


_____________________________

Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184
  • 1
    Thanks for your reply 1. Do you mean with that, that I dont need to call `startMonitoringSignificantLocationChanges`? Somehow I dont know what you want to say with that... I know that significant location updates are available in background. 2. I already registered the application for background tasks via the Info.plist entry "Required background modes" => "App registers for location updates" and the applicationWillTerminate wont be called... – android Jan 31 '12 at 10:38
  • 1
    NO you have to call `startMonitoringSignificantLocationChanges` if you want to receive location updates when your app is in background.
    Just run a background task for you help m editing ans...
    – Inder Kumar Rathore Jan 31 '12 at 10:51
  • Could you please explain your code, cause I dont understand what or why because of this code `the applicationWillTerminate:`is always called. – android Feb 01 '12 at 14:51
  • 1
    I have no idea why it is being called when we have background task and why it is not being called when we don't have any background task. I can just guess that in background task..app is in background and when app is performing something we can save that background task data in `applicationWillTerminate:` method. I haven't seen any docs related to this.it's just my luck that i came to know about this.. – Inder Kumar Rathore Feb 01 '12 at 15:49
  • 1
    Ok sounds logical. Thanks a lot! – android Feb 02 '12 at 07:35