如何处理iOS 4.3中的MKReverseGeocoder / PBHTTPStatusCode = 503错误?
从iOS 4.3(GM种子10M2518)我使用MKReverseGeocoder
时崩溃。 reverseGeocoder:didFailWithError:
被这样的错误经常调用:
Error Domain=NSURLErrorDomain Code=-1011 "The operation couldn't be completed. (NSURLErrorDomain error -1011.)" UserInfo=0x339900 {PBHTTPStatusCode=503}
应用程序往往在这些时刻崩溃。 在以前的iOS版本中,情况并非如此。
任何想法发生了什么?
确保在出现故障时不提前释放反向地址parsing器:
在-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
[_reverseGeocode autorelease]
[_reverseGeocoder release]
更改为[_reverseGeocode autorelease]
-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
解决了我的问题。
Google不允许单个设备在60秒内多次检索自己的位置,因此当(MKReverseGeocoder *)geocoder didFailWithError时,使用另一个方法(需要http请求,需要JSON)。
它在4.3.3(3GS)上为我工作,连续检测用户的位置30-40次,没有崩溃,希望它有帮助!
- (void) retrieveCurrentLoc { self.geoCoder = [[[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate] autorelease]; geoCoder.delegate = self; [geoCoder start]; } - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{ NSString *fetchURL = [NSString stringWithFormat:@"http://maps.google.com/maps/geo? q=%@,%@&output=json&sensor=true", [NSString stringWithFormat:@"%f",mapView.userLocation.location.coordinate.latitude], [NSString stringWithFormat:@"%f",mapView.userLocation.location.coordinate.longitude]]; NSURL *url = [NSURL URLWithString:fetchURL]; NSString *htmlData = [NSString stringWithContentsOfURL:url]; SBJsonParser *parser = [[SBJsonParser alloc] init]; NSDictionary *json = [parser objectWithString:htmlData error:nil]; NSArray *placemark = [json objectForKey:@"Placemark"]; if ([[[[[placemark objectAtIndex:0] objectForKey:@"AddressDetails"]objectForKey:@"Country"]objectForKey:@"Thoroughfare"]objectFor Key:@"ThoroughfareName"] != NULL){ currentAddress = [[[[[placemark objectAtIndex:0] objectForKey:@"AddressDetails"]objectForKey:@"Country"]objectForKey:@"Thoroughfare"]objectFor Key:@"ThoroughfareName"];} else { currentAddress = [[placemark objectAtIndex:0] objectForKey:@"address"]; } }
同样的问题在这里,我们检查了各种解决scheme,没有工作。 503响应代码的处理方式与以前的操作系统不同,您可以轻松注意到通过嗅探iPhonestream量。
依赖于MKReverseGeocoder(如Gowalla)的应用程序将对苹果公司施加一些压力…所以我期望这些日子会有一个4.3.1的修补程序。 或Google用苹果请求更改他们的SLA。
继zippo77的回答之后,我发现在将MKReverseGeocoder委托设置为nil时,最好的结果是-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
_reverseGeocoder.delegate = nil; [_reverseGeocoder autorelease];
我有同样的问题,即使我的MKReverseGeocoder
代码遵循苹果的例子之一( MKReverseGeocoder
作为一个全球性的autorelease
variables)。 此外,这个问题只出现在iOS 4.3(4.0运行没有问题)。
什么解决了我的问题是删除autorelease
部分和释放MKReverseGeocoder
只dealoc
视图。
在地理编码器find地标之前,您可能已经停止了位置pipe理器。 在didFindPlacemark中执行或出错