我在iOS 7上运行良好的应用程序无法使用iOS 8 SDK。
CLLocationManager 没有返回位置,我也没有在Settings -> Location Services
下看到我的应用。我在这个问题上进行了谷歌搜索,但没有出现任何问题。可能有什么不对?
答案 0 :(得分:0)
在info.plist
键:NSLocationWhenInUseUsageDescription
类型:String
值:提示消息例如 - 需要您当前的位置
答案 1 :(得分:0)
在ios 8+中,您需要在应用时仅向我们请求权限[self.locationManager requestWhenInUseAuthorization]
,并且[self.locationManager requestAlwaysAuthorization]
始终使用位置
此代码完美适用于ios 8
#pragma mark -
#pragma mark CLLocationManagerDelegate
- (void)startSignificantChangeUpdates
{
if ([CLLocationManager locationServicesEnabled])
{
if (!self.locationManager)
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
// request location when app in use
[self.locationManager requestWhenInUseAuthorization];
[self.locationManager startUpdatingLocation];
}
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
[self.locationManager stopUpdatingLocation];
CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
[geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
for (CLPlacemark * placemark in placemarks) {
NSString *country = placemark.ISOcountryCode;
cityName = [placemark locality];
}
}];
}