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?
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"];
}
}
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With