How to deal with MKReverseGeocoder / PBHTTPStatusCode=503 errors in iOS 4.3?

流过昼夜 提交于 2019-11-27 16:45:27

问题


Since iOS 4.3 (GM Seed 10M2518) I'm getting crashes when using MKReverseGeocoder. reverseGeocoder:didFailWithError: gets called with an error like this quite often:

Error Domain=NSURLErrorDomain Code=-1011 "The operation couldn’t be completed. (NSURLErrorDomain error -1011.)" UserInfo=0x339900 {PBHTTPStatusCode=503}

The app tends to crash at these moments. This hasn't been the case in previous versions of iOS.

Any ideas what happened?


回答1:


Make sure you don't release the reverse geocoder prematurely on failure:

Changing [_reverseGeocoder release] to [_reverseGeocode autorelease] in -(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error fixed the problem for me.




回答2:


Google doesn't allow a single device to retrieve its location more than once within 60 sec, hence working with another method (http request instead, JSON needed) when (MKReverseGeocoder *)geocoder didFailWithError.

It works for me on 4.3.3 (3GS) and tested for 30-40 times retrieving user's location consecutively without a crash, hope it helps!

- (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"];
    }
}



回答3:


Same problem here, we checked various solutions and didn't work. The 503 response code is handled differently by the previous OS, you can easily notice that by sniffing the iPhone traffic.

Applications that rely on MKReverseGeocoder (like Gowalla) will make some pressure against Apple ... so I would expect a 4.3.1 hotfix coming these days. Or Google to change their SLA with Apple requests.




回答4:


Following on from zippo77's answer, I found best results when setting the MKReverseGeocoder delegate to nil first in -(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error

_reverseGeocoder.delegate = nil;
[_reverseGeocoder autorelease];



回答5:


I had the same issue, even though my MKReverseGeocoder code followed one of the Apple examples (MKReverseGeocoder as a global autorelease variable). Also the issue appeared only on iOS 4.3 (4.0 was running no problem).

What solved the problem for me was removing the autorelease part and releasing the MKReverseGeocoder only in dealoc of the view.




回答6:


Probably you are stoping location manager before geo coder will find placemark. Do it in didFindPlacemark or for error



来源:https://stackoverflow.com/questions/5232822/how-to-deal-with-mkreversegeocoder-pbhttpstatuscode-503-errors-in-ios-4-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!