2017-10-30 11 views
0

私のアプリをiOS 11用に32ビットから64ビットに変換するときに問題がある。 インストールの初めに、許可を求めない場所を取得する。 その後、私のアプリは許可を得ることができません。検索した後、私はキー "NSLocationAlwaysAndWhenInUseUsageDescription"を追加し、それは働いた。iosポップアップ私は自分のiPhoneを回すまでノンストップで場所の許可表示を要求する

しかし、アプリをリリースするときにインストールを試みて、再度確認してください。ポップアップがループ内にあるように複数回表示されるという問題があります。これはシミュレータには表示されません。詳細については、私はそれだけで1時間を表示し、デバッグに同じデバイス上でご確認Video

で確認することができますが、アーカイブIPAファイルを使用して、この問題が表示さアップをします。

のInfo.plist

<key>NSLocationAlwaysAndWhenInUseUsageDescription</key> 
<string></string> 
<key>NSLocationAlwaysUsageDescription</key> 
<string></string> 
<key>NSLocationWhenInUseUsageDescription</key> 
<string></string> 

コールstartUpdatingLocation方法で。

(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { 
switch (status) { 
    case kCLAuthorizationStatusAuthorizedAlways: 
    case kCLAuthorizationStatusAuthorizedWhenInUse: 
     [locationManager startUpdatingLocation]; 
     break; 
    default: 
     break; 
} 

}

方法didUpdateToLocation

(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 
//NSLog(@"Location:%@", newLocation); 
[location release]; 
[locationDate release]; 
location = [newLocation retain]; 
locationDate = [[NSDate date] retain]; 
[locationDelegate locationSucceed:self]; 

if (isOneStop) { 
    [self performSelector:@selector(locationRelease) withObject:nil afterDelay:0.1f]; 
} 

}

ソースコード呼び出し "requestAlwaysAuthorization"。

- (void)startLocation:(NSObject<EpLocationDelegate>*)delegate { 
     NSLog(@"startLocation"); 
     [locationManager stopUpdatingLocation]; 

     [locationDelegate release]; 
     locationDelegate = [delegate retain]; 


     locationManager = [[CLLocationManager alloc] init]; 

     locationManager.delegate = self; 
     locationManager.distanceFilter = kCLDistanceFilterNone; 
     locationManager.desiredAccuracy = kCLLocationAccuracyBest; 

     float osVersion = [[[UIDevice currentDevice] systemVersion] floatValue]; 
     if (osVersion >= 8.0) { 
      [locationManager requestAlwaysAuthorization]; 
     } else { 
    [locationManager startUpdatingLocation]; 
} 

}

startLocation私はviewDidLoadstartLocationを呼び出そうとしていると、まだ私の問題を解決することはできません機能で呼び出し "viewWillAppear"

更新

を持っています。

+0

あなたの応答をありがとう 'requestAlwaysAuthorization' – Paulw11

+0

@ Paulw11呼び出すコードを表示してください。 私は自分の質問を更新しました。 'requestAlwaysAuthorization'はviewWillAppearメソッドで呼び出しを行います。 –

+2

'viewWillAppear'はそれを置くのに悪い場所です。私は 'viewDidLoad'を提案します。また、 'locationManager'はどのように宣言され割り当てられていますか? – Paulw11

答えて

0

あなたのInfo.plistファイルでは、これを追加します。

<key>NSLocationUsageDescription</key> 
<string></string> 
<key>NSLocationWhenInUseUsageDescription</key> 
<string></string> 
Now in your swift file, don't forget to add delegate: CLLocationManagerDelegate 

In your viewDiDLoad(), add this: 

locationManager = CLLocationManager() 

locationManager.delegate = self 

locationManager.requestWhenInUseAuthorization() 

locationManager.desiredAccuracy = kCLLocationAccuracyBest 

locationManager.startUpdatingLocation() 

locationManager.startMonitoringSignificantLocationChanges() 

// Here you can check whether you have allowed the permission or not. 

if CLLocationManager.locationServicesEnabled() 
    { 
     switch(CLLocationManager.authorizationStatus()) 
     { 

     case .authorizedAlways, .authorizedWhenInUse: 

      print("Authorize.") 

      break 

     case .notDetermined: 

      print("Not determined.") 

      break 

     case .restricted: 

      print("Restricted.") 

      break 

     case .denied: 

      print("Denied.") 
     } 
    } 
関連する問題