2016-09-26 72 views
3

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

这里是我的代码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文件之前的作品,

<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> 
+0

,你在的appdelegate叫这个startLocationManager –

+0

@ Anbu.Karthik .. didlaunch –

+0

您可以将您的项目 –

回答

1

无论iOS的10的,你应该开始自己的位置只有在获得了许可后更新,您还应该在请求权限之前检查权限是否已被授予:

-(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; 
    } 
} 
+0

好吧,让我试试这个 –

0

可能是您可以尝试下面的检查,看看是否有帮助:

不要每次调用requestWhenInUseAuthorization

同时检查locationServicesEnabledauthorizationStatus,呼吁requestWhenInUseAuthorization只有authorizationStatuskCLAuthorizationStatusDeniedlocationServicesEnabled回报false

一样,

if(![CLLocationManager locationServicesEnabled] && 
    [CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) 
{ 
    if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { 

     [self.locationManager requestWhenInUseAuthorization]; 

    } 
} 

希望这将有助于:)

+1

你确定..我也试试这个,并检查是否有帮助..谢谢 –