David Castro
David Castro

Reputation: 738

Getting Background Location Without using location services IOS

I got my app rejected because

We found that your app uses a background mode but does not include functionality that requires that mode to run persistently. This behavior is not in compliance with the App Store Review Guidelines.

We noticed your app declares support for location in the UIBackgroundModes key in your Info.plist but does not include features that require persistent location.

I need to track the user location in the background in order to fire a notification if the user is near one of his/her pictures on the application. That's why I used background mode key on my .plist

This how I initialize my locationManager

_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
_locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
_locationManager.distanceFilter = 1000; // Will update evert 1 KM.
_locationManager.activityType = CLActivityTypeFitness;
_locationManager.pausesLocationUpdatesAutomatically = YES;
[_locationManager startUpdatingLocation];

And I'm using didUpdateToLocation to receive the location on the background.

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    if (_currentLocation == nil){
        self.currentLocation = newLocation;
    }else{

        if([self.currentLocation distanceFromLocation:newLocation]){
            [self getNearPicturesMethod:newLocation];
        }
    }

}

They pointed to me that I should use "startMonitoringSignificantLocationChanges" but still if I remove the background key (what they want) the app won't receive location updates anymore if it's on the foreground, they present only if the user opens it and that doesn't work for me.

PS. I read related questions but nobody seemed to fix this problem or to provide a workaround.

Upvotes: 2

Views: 603

Answers (1)

Dean Davids
Dean Davids

Reputation: 4214

Your app will wake on significant location changes. You do not need the background location mode key set for that. Same goes for region boundary monitoring.

For your case, I think you will more likely want to set regions for the nearest pictures and then just wait for boundaries to be crossed.

Use significant location changes to update the nearest pictures and reset your regions to those.

This will work as intended, be within the guidelines of Apple docs and impact the battery of the user very little, if any.

Upvotes: 0

Related Questions