开发者

CLLocation Manager not prompting user

开发者 https://www.devze.com 2023-01-09 21:05 出处:网络
I am using a method to create a location manager if it doesn\'t exist and st开发者_JAVA技巧art it. It checks if the user has location services disabled and respects that unless a BOOL is given to star

I am using a method to create a location manager if it doesn't exist and st开发者_JAVA技巧art it. It checks if the user has location services disabled and respects that unless a BOOL is given to start the services anyway. The method returns a BOOL to indicate services have been started or not.

This works fine for starting the service and prompting the user the first time. If they tap allow things proceed as normal and if they tap don't allow I present a view to input location manually.

However I would like the user to be able to change their mind about using location services so I have a button to allow them to go back to using GPS. It calls the same function again, but this time ignores the users location services preference. I believe this should prompt the user to allow/disallow again, but I am getting an immediate kCLDenied error code instead.

Based on http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html#//apple_ref/doc/uid/TP40009497-CH2-SW11 I would expect another user prompt, not an immediate error.

- (BOOL)startLocationServices:(BOOL)ignorePrefs
{
//    
//    /*UNREVISEDCOMMENTS*/
//    
if (locationManager == nil)
{
    if ([CLLocationManager locationServicesEnabled] || ignorePrefs)
    {
        locationManager    =    [[CLLocationManager alloc] init];
        [locationManager setDelegate:self];
        [locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
        [locationManager setDistanceFilter:10.0];
    }
    else
    {
        return NO;
    }
}
[locationManager startUpdatingLocation];
return YES;
}

(My location manager delegate releases and sets location manager to nil if a denied error is received.)


The user will not receive another prompt message. It just the way the iPhone handle things.

You also have to differentiate between:

  • User disable location services from the Settings application (this status is returned by the + (BOOL)locationServicesEnabled method)
  • User declined usage of the location tracking for the current app (+ (CLAuthorizationStatus)authorizationStatus method returns the current status)

I would check both methods and in case show an alertview with a message, about deactivated location services.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号