iphone:随机调用 CLLocation deletgate 方法

发布于 2024-11-28 04:17:43 字数 1289 浏览 1 评论 0原文

我正在使用 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";
    }
}

I am using CLLocationManager to grab the location.Though I have GPS settings working on my device, it shows the status popup randomly which is defined in didFailWithError

Error I am getting is,

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";
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

又爬满兰若 2024-12-05 04:17:43

只需找出错误​​是什么

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.

Just find out whats the error

if([[error code] isEqualTo: kCLErrorLocationUnknown])
{
   The location manager was unable to obtain a location value right now.
}

other error codes

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文