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

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

提问人:Bhumesh Purohit 提问时间:6/14/2016 更新时间:6/15/2016 访问量:1505

问:

我在我的应用程序中运行以查找当前位置,但第一次返回正确的纬度长度,并且有依赖的位置,但是当他们 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)”

IOS 的Objective-C iPhone 的iOS7 IOS5

评论

0赞 Vishnu gondlekar 6/14/2016
你在模拟器上运行它吗?
0赞 Dominic 6/14/2016
你看过这个答案吗?stackoverflow.com/questions/1409141/......
0赞 Bhumesh Purohit 6/14/2016
不,我正在iPad,iPhone5s,iPhone6上尝试。
0赞 Bhumesh Purohit 6/14/2016
@Dominic 我看到你的建议,但我不满意,你能给我更多吗?
0赞 Bhumesh Purohit 6/14/2016
@Vishnugondlekar我正在尝试不同的ios设备,但没有任何变化

答:

0赞 Bhumesh Purohit 6/15/2016 #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];
//}

现在它运行正常。