didFailWithError:错误域= kCLErrorDomain代码= 0"操作无法完成。 (kCLErrorDomain错误0。)"在ios8设备上不是模拟器

时间:2015-02-11 04:50:06

标签: ipad ios8

我最初几次使用我的iOS8代码获得正确的坐标但是在大约一分钟或几秒钟后我开始出现此错误:

didFailWithError: Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"

我在iPad上调试而不是我的模拟器。

有没有人有同样的问题?

    if(IS_OS_8_OR_LATER){
        NSUInteger code = [CLLocationManager authorizationStatus];
        if (code == kCLAuthorizationStatusNotDetermined && ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)] || [locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])) {
            // choose one request according to your business.
            if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"]){
                [locationManager requestAlwaysAuthorization];
            } else if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]) {
                [locationManager  requestWhenInUseAuthorization];
            } else {
                NSLog(@"Info.plist does not contain NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription");
            }
        }
        [locationManager startUpdatingLocation];
}

    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
    {
    NSLog(@"didUpdateToLocation: %@", newLocation);
    CLLocation *currentLocation = newLocation;

    if (currentLocation != nil) {
        currX = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
        currY = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];

    }
}

0 个答案:

没有答案