【问题标题】:Location Services Stop working after reinstall with iOS10重新安装 iOS10 后位置服务停止工作
【发布时间】:2016-11-29 03:14:25
【问题描述】:

在我卸载 iOS10 应用后,定位服务停止工作。我在 Info.plist 中设置了描述,所以这让我感到困惑,为什么位置服务会停止工作。该应用程序未显示在“设置”->“隐私”->“位置服务”中

<key>NSLocationAlwaysUsageDescription</key>
<string>This app needs to use your location so that it may send it to your selected contacts.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs to use your location so that it may send it to your selected contacts.</string>

使用以下代码检查状态显示状态未确定。

if ([CLLocationManager locationServicesEnabled]) {
    if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusRestricted) {
        NSLog(@"RESTRICTED");
    } else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
        NSLog(@"DENIED");
    } else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
        NSLog(@"NOT DETERMINED");
    } else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways) {
        NSLog(@"ALWAYS");
    } else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse) {
        NSLog(@"WHEN IN USE");
    }
}

编辑: viewController viewDidLoad 方法包含以下代码:

- (void)viewDidLoad {
    [self.locationManager requestAlwaysAuthorization];
    [self.locationManager requestWhenInUseAuthorization];
    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    self.locationManager.delegate = self;

    if ([CLLocationManager locationServicesEnabled]) {
        if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusRestricted) {
            NSLog(@"RESTRICTED");
        } else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
            NSLog(@"DENIED");
        } else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
            NSLog(@"NOT DETERMINED");
        } else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways) {
            NSLog(@"ALWAYS");
        } else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse) {
            NSLog(@"WHEN IN USE");
        }
    }
}

【问题讨论】:

    标签: ios objective-c core-location ios10


    【解决方案1】:

    您需要使用[yourLocationManager startUpdatingLocation],它会提示使用位置的警报。

    在那之前authorizationStatus 将是kCLAuthorizationStatusNotDetermined

    编辑

    self.locationManager = [[CLLocationManager alloc] init]; 
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
    [self.locationManager requestAlwaysAuthorization]; 
    self.locationManager.delegate = self;
    

    添加这个

    【讨论】:

    • 我运行 [_locationManager startUpdatingLocation];当按下按钮时,它不起作用或请求用户许可。我在 viewDid Load 中有以下内容: self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; self.locationManager.delegate = self;并且 didUpdateToLocation 不会被触发。
    • 你添加了 [self.locationManager requestAlwaysAuthorization] 或 [self.locationManager requestWhenInUseAuthorization] 吗?
    • [self.locationManager requestAlwaysAuthorization]; [self.locationManager requestWhenInUseAuthorization]; self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; self.locationManager.delegate = self;
    • 刚刚在我上面的评论中意识到我在请求授权之前初始化了视图控制器。
    【解决方案2】:

    需要查看授权状态,如果是xxx,需要拨打requestAlwaysAuthorization()requestWhenInUseAuthorization()。这将向用户触发警报。

    如果您通过长按应用图标并点击 X 删除了该应用,则会撤销用户使用定位服务的权限,因此该应用将被拒绝访问,直到您再次致电 requestAlwaysAuthorization()requestWhenInUseAuthorization() .

    【讨论】:

      猜你喜欢
      • 2011-09-07
      • 1970-01-01
      • 1970-01-01
      • 2020-11-18
      • 2018-08-16
      • 1970-01-01
      • 1970-01-01
      • 2022-08-24
      • 2016-03-08
      相关资源
      最近更新 更多