2016-09-26 51 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

你確定..我也試試這個,並檢查是否有幫助..謝謝 –