2016-09-26 2 views
3

в iOS 10, иногда при установке приложения запросы разрешения на доступ открывают много времени и висят все приложение и не могут двигаться дальше.Диалоговое окно разрешения местоположения запрашивает много времени в iOS 10

вот мой код, который работает до того прошивка 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

где вы назвали этот startLocationManager –

+0

@ Anbu.Karthik в AppDelegate .. didlaunch –

+0

вы можете прикрепить ваш проект –

ответ

1

Независимо от прошивки 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 каждый раз.

проверка как locationServicesEnabled и authorizationStatus, требуют requestWhenInUseAuthorization только если authorizationStatus является kCLAuthorizationStatusDenied и locationServicesEnabled возвращение false.

Мол,

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

     [self.locationManager requestWhenInUseAuthorization]; 

    } 
} 

Надеется, что это поможет :)

+1

ya sure .. Я тоже попробую это и проверить, поможет ли это. Спасибо –

Смежные вопросы