IOS错误:错误域=kCLErrorDomain代码=0。(kCLErrorDomain错误0.)和#x201D;
我尝试获取用户当前位置的经纬度,我的代码如下:IOS错误:错误域=kCLErrorDomain代码=0。(kCLErrorDomain错误0.)和#x201D;,ios,core-location,cllocationmanager,Ios,Core Location,Cllocationmanager,我尝试获取用户当前位置的经纬度,我的代码如下: - (void)viewDidLoad { self.locationManager=[[CLLocationManager alloc]init]; [locationManager setDelegate:self]; [locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters]; [locationManager startUp
- (void)viewDidLoad {
self.locationManager=[[CLLocationManager alloc]init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
[locationManager startUpdatingLocation];
}
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
float latitude=newLocation.coordinate.latitude;
float longitude=newLocation.coordinate.longitude;
NSLog(@"%f",latitude);
NSLog(@"%f",longitude);
[locationManager stopUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"didFailWithError: %@", error);
}
我总是从didFailWithError方法中得到这个错误:
didFailWithError: Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"
我想,
您需要在项目的.plist
中添加以下权限
nslocationwhenUsageDescription
且该值为应用程序希望使用您的位置时
二是增加[locationManager请求使用授权]代码>代码中的行。
我添加了以下代码:
我想,,
您需要在项目的.plist
中添加以下权限
nslocationwhenUsageDescription
且该值为应用程序希望使用您的位置时
二是增加[locationManager请求使用授权]代码>代码中的行。
我添加了以下代码:
我重置了网络,但仍然不工作@derpoliuk@Mr.Bond请在模拟器调试>位置>当前位置中检查您的位置,该位置也不工作。@bhavinramani@Mr.Bond您是否在模拟器或xcode中设置了当前位置?是否在项目的.plist中添加NSLocationWhenUsageDescription此项?如果您忘记了,请将此密钥和值添加到.plist nslocation whenUsageDescription=应用程序希望使用您的位置i重置网络但仍不工作@derpoliuk@Mr.Bond请在模拟器调试>位置>当前位置中检查您的位置,该位置也不工作。@bhavinramani@Mr.Bond您是否在模拟器或xcode中设置了当前位置?是否在项目的.plist中添加NSLocationWhenUsageDescription此项?如果您忘记了,请在.plist nslocationwhenUsageDescription=应用程序希望使用您的位置时将此键和值添加到.plist nslocation中
- (void)viewDidLoad {
self.locationManager=[[CLLocationManager alloc]init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
[locationManager requestWhenInUseAuthorization];
[locationManager startUpdatingLocation];
}