IOS 9 期:CLGeocoder 网络错误代码 2
IOS 9 issue : CLGeocoder Network error code 2
CLLocation *location =[[CLLocation alloc]initWithLatitude:latitude longitude:longitude];
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"Finding address");
if (error) {
NSLog(@"Error %@", error.description);
} else {
NSLog(@"%@",placemarks[0]);
}
}]; }
enum CLError : Int {
case LocationUnknown
case Denied
case Network
case HeadingFailure
case RegionMonitoringDenied
case RegionMonitoringFailure
case RegionMonitoringSetupDelayed
case RegionMonitoringResponseDelayed
case GeocodeFoundNoResult
case GeocodeFoundPartialResult
case GeocodeCanceled
case DeferredFailed
case DeferredNotUpdatingLocation
case DeferredAccuracyTooLow
case DeferredDistanceFiltered
case DeferredCanceled
case RangingUnavailable
case RangingFailure
}
这里我在 IOS 9 设备中遇到一个错误(在模拟器中它运行良好 ;-))
ERROR during geocode: Error Domain=kCLErrorDomain Code=2 "The
operation couldn’t be completed. (kCLErrorDomain error 2.)"
docs 说 "you should not send more than one geocoding request per minute"。
kCLErrorNetwork The network was unavailable or a network error occurred.
实际上代码在 IOS8
和 IOS7
中运行良好.. 它只在 IOS 9.
中给出 Error
它工作完美。
CLGeocoder *geoCoder = [[CLGeocoder alloc] init];
[geoCoder cancelGeocode];
[geoCoder reverseGeocodeLocation:locationManager.location
completionHandler:^(NSArray *placemarks, NSError *error)
{
NSLog(@"Error is %@",error.localizedDescription);
for (CLPlacemark *placemark in placemarks) {
NSLog(@"%@",placemark.ISOcountryCode);
}
}];
O/p:
错误为 (null)
美国
CLLocation *location =[[CLLocation alloc]initWithLatitude:latitude longitude:longitude];
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"Finding address");
if (error) {
NSLog(@"Error %@", error.description);
} else {
NSLog(@"%@",placemarks[0]);
}
}]; }
enum CLError : Int {
case LocationUnknown
case Denied
case Network
case HeadingFailure
case RegionMonitoringDenied
case RegionMonitoringFailure
case RegionMonitoringSetupDelayed
case RegionMonitoringResponseDelayed
case GeocodeFoundNoResult
case GeocodeFoundPartialResult
case GeocodeCanceled
case DeferredFailed
case DeferredNotUpdatingLocation
case DeferredAccuracyTooLow
case DeferredDistanceFiltered
case DeferredCanceled
case RangingUnavailable
case RangingFailure
}
这里我在 IOS 9 设备中遇到一个错误(在模拟器中它运行良好 ;-))
ERROR during geocode: Error Domain=kCLErrorDomain Code=2 "The operation couldn’t be completed. (kCLErrorDomain error 2.)"
docs 说 "you should not send more than one geocoding request per minute"。
kCLErrorNetwork The network was unavailable or a network error occurred.
实际上代码在 IOS8
和 IOS7
中运行良好.. 它只在 IOS 9.
Error
它工作完美。
CLGeocoder *geoCoder = [[CLGeocoder alloc] init];
[geoCoder cancelGeocode];
[geoCoder reverseGeocodeLocation:locationManager.location
completionHandler:^(NSArray *placemarks, NSError *error)
{
NSLog(@"Error is %@",error.localizedDescription);
for (CLPlacemark *placemark in placemarks) {
NSLog(@"%@",placemark.ISOcountryCode);
}
}];
O/p:
错误为 (null)
美国