I am trying to get locations while my app is in the background. Everything works great when I am using my app. I can also switch to any other app (even the home screen) and the locations still come in. If I am using my phone but my app is in the background location updates seem to come in just fine as long as my phone is active (not locked).
However if I lock the phone and I come back after about 10 minutes the location icon in the status bar and my app is no longer getting location updates.
I have checked for an app crash and there is no crash report. My app also still appears in the app list so I don't think it crashed.
Should GPS stay on forever if I have asked for 'Always' permission. Or does the OS turn it off after the phone has been asleep for a while?
Here is are the entries in my plist:
<key>NSLocationAlwaysUsageDescription</key>
<string></string>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
And here is a screenshot of background location services on:
Here is my custom class that is the location manager delegate:
@interface LocationDelegate ()
@property (nonatomic, strong) CLLocationManager *locationManager;
@end
@implementation LocationDelegate
+ (instancetype) singleton {
static LocationDelegate *delegate = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
delegate = [[self alloc] init];
});
return delegate;
}
- (id) init {
if (self = [super init]) {
// for now filter and accuracy are based on the same preference
_locationManager = [[CLLocationManager alloc] init];
_locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
_locationManager.delegate = self;
// Check for iOS 8
if ([_locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[_locationManager requestAlwaysAuthorization];
}
return self;
}
Notice that it is a singleton. Does that matter? Is this class getting cleaned up after my app has been in the background for a while or suspended? From what I have read I don't think singletons like this get cleaned up as they are strong references so I don't think that is the problem...but I really have no idea why I stop getting locations after a certain amount of time.
EDIT:
Seems that my location manager is pausing location updates after some time. The big issue that that I am not getting a resume call.
I have the activityType set to the default of
CLActivityTypeOther
I can try other activityTypes to see if that will make a difference. However I am relying on my app to work for walking, and driving.
I think I am running into the same problem as this: