今天写个定位,本来很简单,但是在填写plist时,通过系统提示,只能看到NSLocationUsageDescription项目,根本不提示
(1)NSLocationAlwaysUsageDescription
(2)NSLocationWhenInUseUsageDescription
这2个项目,所以我就用了NSLocationUsageDescription,结果就不能定位了。其实NSLocationUsageDescription这个项目在ios8就不用了!
下面简单地说一下用法:
_locationManager = [[CLLocationManager alloc] init]; _locationManager.delegate = self; _locationManager.distanceFilter=kCLDistanceFilterNone; _locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation; [_locationManager requestWhenInUseAuthorization]; [_locationManager requestLocation];
下面是取到gps后,解析出所在国家代码
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{ NSLog(@"locations is %@",locations); CLGeocoder *geocoder = [[CLGeocoder alloc] init]; [geocoder reverseGeocodeLocation:[locations lastObject] completionHandler:^(NSArray *placemarks, NSError *error){ if(error != nil) { NSLog(@"CLGeocoder error :%@ ",error); } else//if we can get place info ,we set it into meteData dic with kCGImagePropertyExifCameraOwnerName key { if(placemarks.count > 0) { CLPlacemark *placemark = [placemarks objectAtIndex:0]; NSString *countCodeStr = placemark.ISOcountryCode; NSLog(@"countCodeStr is %@",countCodeStr); } } }]; }