如何处理 iOS 4.3 中的 MKReverseGeocoder / PBHTTPStatusCode=503 错误?

发布于 2024-10-21 00:03:36 字数 351 浏览 2 评论 0原文

从 iOS 4.3 (GM Seed 10M2518) 开始,我在使用 MKReverseGeocoder 时遇到崩溃。 reverseGeocoder:didFailWithError: 经常被调用并出现这样的错误:

Error Domain=NSURLErrorDomain Code=-1011 “操作无法完成。(NSURLErrorDomain 错误 -1011。)” UserInfo =0x339900 {PBHTTPStatusCode=503}

应用程序在这些时刻往往会崩溃。 在之前的 iOS 版本中,情况并非如此。

有什么想法发生了什么吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

时光礼记 2024-10-28 00:03:36

确保失败时不会过早释放反向地理编码器:

-(void)reverseGeocoder:(MKReverseGeocoder 中的 [_reverseGeocoder release] 更改为 [_reverseGeocode autorelease] *)geocoder didFailWithError:(NSError *)error 为我解决了这个问题。

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.

花开雨落又逢春i 2024-10-28 00:03:36

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

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"];
    }
}
夜访吸血鬼 2024-10-28 00:03:36

同样的问题,我们检查了各种解决方案,但没有成功。以前的操作系统对 503 响应代码的处理方式有所不同,您可以通过嗅探 iPhone 流量轻松注意到这一点。

依赖 MKReverseGeocoder(如 Gowalla)的应用程序将对 Apple 造成一些压力……所以我预计近期会发布 4.3.1 修补程序。或者 Google 根据 Apple 的要求更改其 SLA。

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.

ζ澈沫 2024-10-28 00:03:36

根据 zippo77 的回答,我在 -(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error 中首先将 MKReverseGeocoder 委托设置为 nil 时发现了最佳结果

_reverseGeocoder.delegate = nil;
[_reverseGeocoder autorelease];

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];
小苏打饼 2024-10-28 00:03:36

我遇到了同样的问题,即使我的 MKReverseGeocoder 代码遵循 Apple 示例之一(MKReverseGeocoder 作为全局 autorelease 变量)。此外,该问题仅出现在 iOS 4.3 上(4.0 运行没有问题)。

对我来说解决问题的方法是删除 autorelease 部分并仅在视图的 dealoc 中释放 MKReverseGeocoder

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.

太阳哥哥 2024-10-28 00:03:36

也许您正在地理编码器找到地标之前停止位置管理器。在 didFindPlacemark 中执行此操作或出现错误

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文