位置权限对话框在iOS 10中提示了大量时间 [英] Location permission dialog prompts lots of time in iOS 10

查看:96
本文介绍了位置权限对话框在iOS 10中提示了大量时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 10中,有时在安装应用时,位置权限提示会打开大量时间并挂起所有应用并且无法进一步移动。

in iOS 10, sometimes when install the app, location permission prompts opens lots of time and hangs all app and not able to move further.

这是我的代码在iOS 10之前有效

here is my code that works before iOS 10

-(void)startLocationManager{  
    self.locationManager=[[CLLocationManager alloc]init];
    self.locationManager.desiredAccuracy=kCLLocationAccuracyBest;
    self.locationManager.delegate=self;
    if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
        [self.locationManager requestWhenInUseAuthorization];
    }

    [self.locationManager startUpdatingLocation];
}

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
    if (self.myCurrentLocation==nil) {
        self.myCurrentLocation=[locations lastObject];
        [[WALocationManager WALocationSharedInstance] checkLatestLocation];
    }
    else{
        if (self.myCurrentLocation.horizontalAccuracy < 0){
            return;
        }
        self.myCurrentLocation=[locations lastObject];
        if([[WALocationManager WALocationSharedInstance] currentLocation]!=self.myCurrentLocation ){

        }
    }
}

在我的plist文件中,

In my plist file,

<key>NSLocationAlwaysUsageDescription</key>
<string>This app will use your location to get most nearyby activity around you.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app will use your location.</string>


推荐答案

无论iOS 10如何,您都应该开始更新位置只有在授予权限的情况下,您还应该在请求权限之前检查是否已经授予权限:

Regardless of iOS 10, you should start your location updating only if the permission was granted, you should also check if the permission is already granted before requesting permissions:

-(void)startLocationManager{
    self.locationManager=[[CLLocationManager alloc]init];
    self.locationManager.desiredAccuracy=kCLLocationAccuracyBest;
    self.locationManager.delegate=self;
    // Check for current permissions
    [self checkLocationAuth:[CLLocationManager authorizationStatus]];
}

-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{
    [self checkLocationAuth:status];
}


-(void)checkLocationAuth:(CLAuthorizationStatus)status{
    switch (status) {
        case kCLAuthorizationStatusAuthorizedWhenInUse:
        case kCLAuthorizationStatusAuthorizedAlways:
            [self.locationManager startUpdatingLocation];
            break;
            // did not ask for permission, ask now
        case kCLAuthorizationStatusNotDetermined:
            if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
                [self.locationManager requestWhenInUseAuthorization];
            } else { // iOS < 8? implicitly request permission
                [self.locationManager startUpdatingLocation];
            }
            break;
        // Also need to handle failures, etc
        default:
            break;
    }
}

这篇关于位置权限对话框在iOS 10中提示了大量时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆