Domain=kCLErrorDomain Code=0 "(null)" 在任何 ios 设备中

Domain=kCLErrorDomain Code=0 "(null)" in any ios device

我 运行 在我的应用程序中寻找当前位置,但第一次 return 很长一段时间与那里相关的位置但是当他们 didUpdateLocations 那个时间去 didFailWithError 和 return 域=kCLErrorDomain 代码=0“(空)”。我尝试了不同的解决方案,比如

  1. 重置内容和设置
  2. 在Xcode,产品 -> 方案 -> 编辑 Scheme,然后取消"Allow Location Simulator"和iOS 模拟器并重新设置内容和设置,然后重新设置为 Xcode,重复第一个 step.and 到 iOS 模拟器并重置。

但是 none 那项工作

我的代码在这里:

- (void)locationManager:(CLLocationManager *)manager
 didUpdateLocations:(NSArray *)locations{

NSLog(@"didUpdateToLocation: %@", [locations lastObject]);
CLLocation *currentLocation = [locations lastObject];


if (currentLocation != nil)
{
    self.lblLongitude.text = [NSString stringWithFormat:@"%.12f", currentLocation.coordinate.longitude];
    self.lblLatitude.text = [NSString stringWithFormat:@"%.12f", currentLocation.coordinate.latitude];
}


NSLog(@"Resolving the Address");


[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
    NSLog(@"Found placemarks: %@, error: %@", placemarks, error);
    if (error == nil && [placemarks count] > 0) {
        placemark = [placemarks lastObject];
        NSString *geoMapItem = placemark.description;
        NSRange start = [geoMapItem rangeOfString:@"dependentLocality"];

        NSRange end = [geoMapItem rangeOfString:@")" options:NSCaseInsensitiveSearch range:NSMakeRange(start.location, 1000)];
        NSString *dataString = [geoMapItem substringWithRange:NSMakeRange(start.location, end.location - start.location + end.length)];
        dataString = [dataString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
        dataString = [dataString stringByReplacingOccurrencesOfString:@"  " withString:@""];
        dataString = [dataString stringByReplacingOccurrencesOfString:@"\"" withString:@""];

        start = [dataString rangeOfString:@"("];
        end = [dataString rangeOfString:@")"];
        NSLog(@"datastring===>%@",dataString);
        lblAddress.text = [NSString stringWithFormat:@"%@ \n%@ %@\n%@\n%@",
                        dataString,
                        placemark.postalCode, placemark.locality,
                        placemark.administrativeArea,
                        placemark.country];
    } else
    {
        NSLog(@"%@", error.debugDescription);
    }
} ];}

更新位置后第一次进入错误块

-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
NSLog(@"didFailWithError%@",error);
UIAlertView *errorAlert = [[UIAlertView alloc]
                           initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];}

并得到这个错误 didFailWithErrorError Domain=kCLErrorDomain Code=0 "(null)"

大家好,我找到了我自己问题的解决方案。 我犯的一些小错误。我每次都检查 currentLocation != nil,它是更新位置,但未设置当前位置 Lat Long。

//if (currentLocation != nil)
//{
    self.lblLongitude.text = [NSString stringWithFormat:@"%.12f", currentLocation.coordinate.longitude];
    self.lblLatitude.text = [NSString stringWithFormat:@"%.12f", currentLocation.coordinate.latitude];
//}

现在 运行 正确。