2016-06-22 16 views
0

didUpdateLocationsは呼び出されず、代わりにdidFailWithErrorが拒否コードkCLErrorDeniedで呼び出されます。didUpdateLocationsはios 9.3.2で呼び出されません

#import "ViewController.h" 
@import CoreLocation; 

@interface ViewController() <CLLocationManagerDelegate> 
@property (strong, nonatomic) CLLocationManager *locationManager; 
@end 

@implementation ViewController 

- (void)viewDidLoad { 

    [super viewDidLoad]; 

    // Do any additional setup after loading the view, typically from a nib. 

    self.locationManager = [[CLLocationManager alloc] init]; 

    self.locationManager.delegate = self; 

    // Check for iOS 8. Without this guard the code will crash with "unknown selector" on iOS 7. 

    if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { 

     [self.locationManager requestWhenInUseAuthorization]; 

    } 

    [self.locationManager startUpdatingLocation]; 
} 

- (void)didReceiveMemoryWarning { 

    [super didReceiveMemoryWarning]; 

    // Dispose of any resources that can be recreated. 

} 

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(nonnull NSArray<CLLocation *> *)locations 

{ 

    NSLog(@"update"); 

} 

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(nonnull NSError *)error 

{ 

    NSLog(@"error"); 
} 

@end 

アプリのInfo.plistファイルにNSLocationWhenInUseUsageDescriptionNSLocationAlwaysUsageDescriptionを挿入: は、ここで私がやったものです。場所の更新が選択された機能の背景モードを有効にしました。非常に有名なブログpostから助けを得てください。私はLocation Access Requestポップアップを受け取り、アプリケーションが場所にアクセスできるようにします。

しかし、私は位置の更新を取得できませんでした。それはIOS 8でIPADで動作しますが、IOSバージョン9.3.2でipadで動作しません。 IOS 9.3.2でロケーションアップデートを動作させるにはどうすればよいですか?以下の事をしようと

+0

それはdidFailWithError' 'になりますどのようなエラー? –

+0

@Ronak Chaniyara質問を更新しました。私はkCLErrorDeniedを取得します(エラードメイン= kCLErrorDomainコード= 0 "(ヌル)") – Murat

答えて

0

はあなたの問題を解決することがあります。

  • は、設定に移動し、お住まいの地域のサービス
  • は、あなたが持っている場合、また、シミュレータ

を再起動

  • ネットワーク設定をリセットするリセットスキーム/スキームの編集/オプション/ロケーションシミュレーションを許可しますが、デフォルトのロケーションセットはありません。

    常に承認を使用する場合は、文字列としてNSLocationAlwaysUsageDescriptionをplistに追加してください。また、WhenInUse認可を使用している場合と同じ方法でNSLocationWhenInUseUsageDescriptionと同じ操作を行います。ここでは詳しくチェック回答については

    didFailWithError: Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"

    IOS 9 Error Domain=kCLErrorDomain Code=0 "(null)"

  • +0

    私はデバッグに実際のデバイスを使用しています。これは、シミュレータ上のAllow Location Simulationでは動作しますが、実際のデバイスでは動作しません。 NSLocationAlwaysUsageDescriptionとNSLocationWhenInUseUsageDescriptionをplistに追加しました。私はほぼすべてのstackoverflowの記事を読んだが、解決策を見つけることができなかった。私はあなたが言ったが働いていないものを適用した。 – Murat

    関連する問題