iphone:CLLocation deletgate方法随机调用
我正在使用iphone:CLLocation deletgate方法随机调用,iphone,objective-c,cllocationmanager,Iphone,Objective C,Cllocationmanager,我正在使用CLLocationManager获取位置。虽然我的设备上有GPS设置,但它会随机显示在didFailWithError中定义的状态弹出窗口 我得到的错误是 Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)" -(void) startGettingCurrentLocation { CLLocationManager *loc
CLLocationManager
获取位置。虽然我的设备上有GPS设置
,但它会随机显示在didFailWithError
中定义的状态弹出窗口
我得到的错误是
Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"
-(void) startGettingCurrentLocation {
CLLocationManager *locationManager=[[CLLocationManager alloc] init];
locationManager.delegate=self;
locationManager.desiredAccuracy=kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];
}
- (void) locationManager:(CLLocationManager *) manager didFailWithError:(NSError *)error {
[locatingAlert dismissWithClickedButtonIndex:0 animated:NO];
UIAlertView *statusAlert;
statusAlert = [[UIAlertView alloc] initWithTitle:@"" message:@"In order to use this application properly, you need to allow use of the GPS." delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
[statusAlert addButtonWithTitle:@"OK"];
[statusAlert show];
//Set Default Coordinates it app not able to get location
if (mainDelegate.currentLatitude == nil) {
mainDelegate.currentLatitude = @"28.6317021";
}
if (mainDelegate.currentLongitude == nil) {
mainDelegate.currentLongitude = @"-81.423110";
}
}
看看有什么错误
if([[error code] isEqualTo: kCLErrorLocationUnknown])
{
The location manager was unable to obtain a location value right now.
}
其他错误代码
kCLErrorLocationUnknown
The location manager was unable to obtain a location value right now.
kCLErrorDenied
Access to the location service was denied by the user.
kCLErrorNetwork
The network was unavailable or a network error occurred.
kCLErrorHeadingFailure
The heading could not be determined.
kCLErrorRegionMonitoringDenied
Access to the region monitoring service was denied by the user.
kCLErrorRegionMonitoringFailure
A registered region cannot be monitored.
kCLErrorRegionMonitoringSetupDelayed
Core Location could not initialize the region monitoring feature immediately.
请看一下您是如何称呼该代表的?我问您是否将cllocationmanager.delegate=self放置在viewdidload中?如果每次更新,为什么要显示警报?相反,您可以删除警报,对吗?编辑问题后,请look@Heena它在模拟器上不起作用。有一些限制,最大的是硬件。你觉得这很奇怪。。