2016-05-06 6 views
0

ここでは私のコードです:コードdidfailwithError(に入るDidupdateLocation()メソッド、iOSの、客観-c、入るない)

if (!self.locationManager) { 
     self.locationManager = [[CLLocationManager alloc] init]; 
     self.locationManager.delegate = self; 
     self.locationManager.desiredAccuracy =  kCLLocationAccuracyNearestTenMeters; 
    } 


if([CLLocationManager locationServicesEnabled]){ 
     [self findCurrentLocation]; 
     } 

-(void)findCurrentLocation { 
    if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) { 

     [self.locationManager performSelector:@selector(requestAlwaysAuthorization)]; 
    } 

    [self.locationManager startUpdatingLocation]; 
} 

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{ 
    self.isLocationEnabled=YES; 
    self.currentLocation = newLocation; 

    if (currentLocation!= nil) { 

     latitudeValue = [NSString stringWithFormat:@"%.8f",currentLocation.coordinate.latitude]; 
     longitudeValue = [NSString stringWithFormat:@"%.8f",currentLocation.coordinate.longitude]; 

    } 
    [self.locationManager stopUpdatingLocation]; 
} 



- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 
{ 
    if([error code] == kCLErrorDenied) 
    { 
     [locationManager stopUpdatingLocation]; 
    } 
    self.isLocationEnabled=NO; 
} 

私はすべてのエラーを得ていないのですが、didUpdateToLocationはそれがある、と呼ばれることはありません行くにdidFailWithError()

私は緯度とlongtitudeのnull値を取得しています。価値を得るために何ができるのか教えてください。 iOS8から上記の

+0

この[質問](http://stackoverflow.com/questions/32375438/locationmanager-not-working-on-ios-9)をチェックし、それはするのに役立ちますあなたの問題を解決してください。 –

+0

'NSLog(@"エラー:%@ "、error.description);' 'locationManager:didFailWithError:'の中に入れてください。出力は何ですか? –

答えて

0

を開始することを求めてロケーションマネージャからあなたのInfo.plistとリクエストの承認にキーを追加します。

NSLocationWhenInUseUsageDescription 

NSLocationAlwaysUsageDescription 

対応するロケーションメソッドの認可をリクエストする必要があります。

[self.locationManager requestWhenInUseAuthorization] 
[self.locationManager requestAlwaysAuthorization] 

このドキュメントをお読みください:http://nevan.net/2014/09/core-location-manager-changes-in-ios-8/

関連する問題