【问题标题】:iphone : CLLocation deletgate method called randomlyiphone:随机调用的 CLLocation 委托方法
【发布时间】:2011-10-20 13:54:08
【问题描述】:

我正在使用CLLocationManager 来获取位置。虽然I have GPS settings working on my device,它会随机显示在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";
    }
}

【问题讨论】:

  • 你怎么称呼那个代表?
  • 我问你是否将 cllocationmanager.delegate=self 放在 viewdidload 中?
  • 为什么每次都更新时要显示警报?相反,您可以删除警报吗?
  • 已编辑问题,请查看

标签: iphone objective-c cllocationmanager


【解决方案1】:

只要找出错误是什么

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.

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-06-03
  • 1970-01-01
  • 1970-01-01
  • 2011-07-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多