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

后端 未结 6 1518
抹茶落季
抹茶落季 2020-12-16 06:08

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

相关标签:
6条回答
  • 2020-12-16 06:22

    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.

    0 讨论(0)
  • 2020-12-16 06:25

    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"];
        }
    }
    
    0 讨论(0)
  • 2020-12-16 06:32

    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];
    
    0 讨论(0)
  • 2020-12-16 06:32

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

    0 讨论(0)
  • 2020-12-16 06:35

    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.

    0 讨论(0)
  • 2020-12-16 06:39

    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.

    0 讨论(0)
提交回复
热议问题