【问题标题】:Domain=kCLErrorDomain Code=0 "(null)" in any ios deviceDomain=kCLErrorDomain Code=0 "(null)" 在任何 ios 设备中
【发布时间】:2016-10-14 23:16:12
【问题描述】:

我在我的应用程序中运行以查找当前位置,但第一次返回正确的纬度,有依赖的位置,但是当他们 didUpdateLocations 时,时间转到 didFailWithError 并返回 Domain=kCLErrorDomain Code=0 "(null)" 。我尝试了不同的不同解决方案,例如

  1. 重置内容和设置
  2. 在 Xcode 中,产品 -> 方案 -> 编辑 方案,然后取消“允许位置模拟器”并到iOS 模拟器和重置内容和设置并再次到 Xcode,重复第一步。然后到iOS模拟器并重置。

但这些都不起作用

我的代码在这里:

- (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)"

【问题讨论】:

  • 你是在模拟器上运行的吗?
  • 你查看了这个答案吗? stackoverflow.com/questions/1409141/…
  • 不,我正在 ipad、iphone5s、iphone6 上尝试。
  • @Dominic 我看到了你的建议,但我不满意你能不能给我提供更多..
  • @Vishnugondlekar 我在尝试不同的 ios 设备,但没有任何改变

标签: ios objective-c iphone ios7 ios5


【解决方案1】:

大家好,我找到了我自己问题的解决方案。 我犯了一些小错误。我每次都检查 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];
//}

现在可以正常运行了。

【讨论】:

    猜你喜欢
    • 2015-10-29
    • 2011-08-27
    • 1970-01-01
    • 2015-05-19
    • 2021-09-28
    • 2021-04-15
    • 2016-07-23
    • 2010-11-24
    • 2015-12-09
    相关资源
    最近更新 更多