2013-03-07 49 views
2

我在Core Location Services中的本地化API存在問題。我收到請求位置服務許可的promt。如果我點擊允許並轉到設置,我可以看到我的應用程序沒有權限。位置服務權限未保存iOS

這是我的代碼在我GeoUtility類:

CLGeocoder *reverseGeocoder = [[CLGeocoder alloc] init]; 

CLLocationManager *lm = [[CLLocationManager alloc] init]; 

[lm setPurpose:@"Need to verify your region"]; 
[lm startUpdatingLocation]; 

它是由一個的viewController在viewDidAppear

我也有我的plist文件添加下所需要的設備Capabilites location-services觸發。

+0

你在哪裏添加了這段代碼? – 2013-03-07 10:28:26

+0

我已更新我的問題 – 2013-03-07 10:30:04

+0

'[CLLocationManager authorizationStatus]'給出了什麼結果? – fguchelaar 2013-03-07 10:31:44

回答

0

添加CoreLocation.framework和MapKit.framework

在.H

#import <MapKit/MapKit.h>

CLLocationManager *locationManager; 
CLGeocoder *geocoder; 

鑑於沒有負載

- (void)viewDidLoad 
{ 
    locationManager = [[CLLocationManager alloc] init]; 
     geocoder = [[CLGeocoder alloc] init]; 
     locationManager.delegate = self; 
     locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
     [locationManager startUpdatingLocation]; 
} 

然後

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{ 
    CLLocation *currentLocation = newLocation; 
    if (currentLocation != nil) { 
     LongitudeLbl.text = [NSString stringWithFormat:@"%.8f",currentLocation.coordinate.longitude]; 
     LatitudeLbl.text = [NSString stringWithFormat:@"%.8f",currentLocation.coordinate.latitude]; 
    } 


[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) { 
     if (error == nil && [placemarks count] > 0) { 
      placemark = [placemarks lastObject]; 
      NSString *addresstemp2 = [[NSString alloc] init]; 
      NSString *subThoroughfare2 = [NSString stringWithFormat:@"%@",placemark.subThoroughfare]; 

      NSString *thoroughfare2 = [NSString stringWithFormat:@"%@",placemark.thoroughfare]; 
      NSString *postalCode2 = [NSString stringWithFormat:@"%@",placemark.postalCode]; 
      NSString *locality2 = [NSString stringWithFormat:@"%@",placemark.locality]; 
      NSString *administrativeArea2 = [NSString stringWithFormat:@"%@",placemark.administrativeArea]; 
      NSString *country2 = [NSString stringWithFormat:@"%@",placemark.country]; 

      if (![subThoroughfare2 isEqualToString:@"(null)"]) { 
       addresstemp2 = [NSString stringWithFormat:@"%@",subThoroughfare2]; 
      } 
      if (![thoroughfare2 isEqualToString:@"(null)"]) { 
       addresstemp2 = [NSString stringWithFormat:@"%@ %@ \n",addresstemp2,thoroughfare2]; 
      } 
      if (![postalCode2 isEqualToString:@"(null)"]) { 
       addresstemp2 = [NSString stringWithFormat:@"%@ %@",addresstemp2,postalCode2]; 
      } 
      if (![locality2 isEqualToString:@"(null)"]) { 
       addresstemp2 = [NSString stringWithFormat:@"%@ %@ \n",addresstemp2,locality2]; 
      } 
      if (![administrativeArea2 isEqualToString:@"(null)"]) { 
       addresstemp2 = [NSString stringWithFormat:@"%@ %@ \n",addresstemp2,administrativeArea2]; 
      } 
      if (![country2 isEqualToString:@"(null)"]) { 
       addresstemp2 = [NSString stringWithFormat:@"%@ %@",addresstemp2,country2]; 
      } 
      AddressLbl.text = [[NSString alloc] initWithString:addresstemp2]; 
      [AddressLbl sizeToFit]; 

      [locationManager stopUpdatingLocation]; 
} else { 
     } 
    } ]; 
} 

你也改變你的模擬器設置通過設置,選擇位置服務將其更改爲ON。向下看是你的應用程序的名稱,如果它關閉,那麼改爲ON