繁体   English   中英

使用iOS10重新安装后,定位服务停止工作

[英]Location Services Stop working after reinstall with iOS10

卸载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");
        }
    }
}

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

在此之前, authorizationStatus将为kCLAuthorizationStatusNotDetermined

编辑

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

加上这个

您需要检查授权状态,如果它是xxx,则需要调用requestAlwaysAuthorization()requestWhenInUseAuthorization() 这将向用户触发警报。

如果您通过长按应用程序图标并点按X来删除该应用程序,则会撤消用户使用位置服务的权限,因此该应用程序将被拒绝访问,直到您再次调用requestAlwaysAuthorization()requestWhenInUseAuthorization()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM