如何检测用户是否拒绝使用我的默认位置?

时间:2013-01-29 10:06:16

标签: iphone ios objective-c core-location

  

可能重复:
  Determining if user has denied CoreLocation permission

我如何在iOS应用中检测用户是否拒绝“使用我的默认位置”?

我想根据他们的选择向他们展示不同的视图控制器。

感谢

4 个答案:

答案 0 :(得分:4)

为此,您需要实现以下委托方法:

- (void)locationManager:(CLLocationManager*)manager didFailWithError:(NSError*)error
{
    if([error code]== kCLErrorDenied)
        self.locationDenied = YES;

        switch ([error code]) {
        // "Don't Allow" on two successive app launches is the same as saying "never allow". The user
        // can reset this for all apps by going to Settings > General > Reset > Reset Location Warnings.
        case kCLErrorDenied:
            [appDelegate showAllowGPSLocationView];
        default:
            break;
    }

    self.locationDefined = NO;
}

您可以在AppDelegate中创建方法“showAllowGPSLocationView”。并向用户显示视图,您需要访问GPS位置。

希望它能解决您的问题。

快乐的编码!

答案 1 :(得分:1)

-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {

    if (status == kCLAuthorizationStatusDenied) {
        // denied
    }
    else if (status == kCLAuthorizationStatusAuthorized) {
        // allowed
    }
}

实施CLLocationManagerDelegate委托 有关详细说明,请参阅here。为我工作。希望它有所帮助..

答案 2 :(得分:1)

您可以尝试如下:

 #if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_4_2
    if ([CLLocationManager locationServicesEnabled] && ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized))  
 #else 
    if ([CLLocationManager locationServicesEnabled])    
 #endif

答案 3 :(得分:1)

我为此解决了问题的方法有两种:首先检查是否启用了位置服务(设备上的第一个位置设置),然后检查用户是否授权了您的应用。

- (bool)locationAvailable
{
    if (!([CLLocationManager locationServicesEnabled]) || ( [CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied))
        return FALSE;
    else
        return TRUE;
}