IOS location manager stops after phone is locked for ~ 10 minutes

I am trying to find locations while my application is in the background. Everything works fine when I use my application. I can also switch to any other application (even on the home screen) and still remain in memory. If I use my phone, but my app is in the background, the updates seem to update very well as long as my phone is active (not locked).

However, if I lock my phone and I come back after 10 minutes, the location icon in the status bar and my app no ​​longer receive location updates.

I have checked for an application crash and there is no crash report. My app also still appears in the app list, so I don't think it crashed.

If GPS stays forever, if I ask for "Always" permission. Or does the OS turn it off after the phone has been sleeping for a while?

Here are the entries in my plist:

<key>NSLocationAlwaysUsageDescription</key>
<string></string>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>

      

And here is a screenshot of the location services on the page:

enter image description here

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;
}

      

Please note that this is a singleton. Does it matter? Is this class cleared after my application has been in the background for a while or suspended? From what I've read, I don't think singles like this get removed as they are strong links, so I don't think this is a problem ... but I really don't know why I stop getting places after a certain amount of time.

EDIT:

It seems that my location manager pauses updating the location after a while. The big problem is that I am not getting a second call.

I have the default activityType

CLActivityTypeOther

I can try other activities to see if this changes. However, I rely on my app to work for walking and driving.

I think I am facing the same problem as this:

iPhone GPS in background never resumes after pause

+3


source to share


3 answers


No, it will not necessarily continue in the background. By default, the setting is pausesLocationUpdatesAutomatically

set to YES, which when combined with activityType

(if installed) will help the OS determine when it is safe to pause location updates to conserve power. You can implement a delegate locationManagerDidPauseLocationUpdates:

for registration if the OS has paused your updates.



Also, to be clear, setting requestAlwaysAuthorization

does not mean that the locationManager will continue to work, it just means that your application can launch the locationManager from foreground or background, or in suspended modes.

+1


source


Yes, it should stay enabled as long as you enable it in BackgroundModes, request requestAlwaysAuthorization

and add NSLocationAlwaysUsageDescription

. However, NSLocationAlwaysUsageDescription

should have a description, your XML looks like you don't have one. Obviously you also need to call startUpdatingLocation.



If you think your singleton might be part of the problem, try moving the code to appDelegate.

0


source


Restarting after a pause will have the same effect as not allowing a pause. Yes, it's a battery, but my only option if I want it to start when the user starts moving again.

0


source







All Articles