-2

My app monitors user location updates (not necessarily significant location change) with:

someLocationManager = [[CLLocationManager alloc] init];
[someLocationManager setDelegate:self];
[someLocationManager startUpdatingLocation];

When app (in simulator) is in foreground everything works ok, but when suspending it to background (not terminating), I get this error to the log:

Can't endBackgroundTask: no background task exists with identifier *, or it may have already been ended

All other answers for this error have no connection to location services, but only generic background task issues.

mllm
  • 17,068
  • 15
  • 53
  • 64
  • It's fine to post your own question/answer but at least make your "question" an actual question. And no need to mention that you are going to answer your own question. – rmaddy Jun 18 '15 at 13:34
  • I think that acting like it's a real question has no benefit. Presenting a real problem - that's the point, and so I did. – mllm Jun 18 '15 at 13:48

2 Answers2

1

So it appears that the following 3 settings should be made in order for background location update to work properly. Do this and fix the problem:

  1. Make NSLocationAlwaysUsageDescription key is set (with value as a reason for the permission) in info.plist.
  2. Make sure to call [someLocationManager requestAlwaysAuthorization]; when asking for permission.
  3. Enable Location Updates in Background Modes in Capabilities section in your target settings. Not sure about this one, but sounds right.

Enjoy!

mllm
  • 17,068
  • 15
  • 53
  • 64
1

Add the below code at the time of getting location authorization from the user. Because apple changed the default allowsBackgroundLocationUpdates NO from iOS9.

'if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9) {
    locationManager.allowsBackgroundLocationUpdates = YES;
}'
Anand3777
  • 448
  • 2
  • 5
  • 16