【发布时间】:2011-05-30 18:08:01
【问题描述】:
我正在调试一个崩溃报告为:
Exception Type: SIGSEGV
Exception Codes: SEGV_ACCERR
崩溃发生在numberOfFails++ 的行上。
该应用使用ASIHTTP。我个人更喜欢使用NSURLConnection。如果它失败了,我永远不会自动重复对NSURLConnection 的请求,因为我从来没有见过它不应该失败的情况。我宁愿只给 UI 一个刷新按钮,或者显示一个带有按钮的 UIAlertView 以重试或类似的东西。
无论如何,为了与其他团队成员合作,我正在寻求解决此问题,而不是暂时将 ASIHTTP 替换为 NSURLConnection。
请求的开始是这样的:
- (void)getResources:(CLLocation *)location withQuery:(NSString *)query {
NSURL *url = [NSURL URLWithString:[NSString stringWithString:@"https://example.com/"]];
self.resourcesAPIRequest = [ASIFormDataRequest requestWithURL:url];
[resourcesAPIRequest setPostValue:[Model instance].oauth_token forKey:@"oauth_token"];
[resourcesAPIRequest setPostValue:[[NSNumber numberWithDouble:location.coordinate.latitude] stringValue] forKey:@"latitude"];
[resourcesAPIRequest setPostValue:[[NSNumber numberWithDouble:location.coordinate.longitude] stringValue] forKey:@"longitude"];
[resourcesAPIRequest setPostValue:query forKey:@"query"];
[resourcesAPIRequest setDelegate:self];
[resourcesAPIRequest setDidFinishSelector:@selector(resourcesAPIReturned:)];
resourcesAPIRequest.userInfo = [NSDictionary dictionaryWithObjectsAndKeys:NSStringFromSelector(@selector(getResources:withQuery:)), @"repeatSelector", location, @"argument1", query, @"argument2", nil];
[resourcesAPIRequest startAsynchronous];
}
我注意到的一件事是: <ASIHTTPRequestDelegate>不在头文件中,但是这个回调方法仍然被调用OK:
#define maximumNumberOfFails 50
- (void)requestFailed:(ASIFormDataRequest *)request {
static int numberOfFails = 0;
if (numberOfFails < maximumNumberOfFails) {
[NSThread sleepForTimeInterval:sleepTimeInSeconds];
if ([request.userInfo objectForKey:@"argument2"]) {
[self performSelector:NSSelectorFromString([request.userInfo objectForKey:@"repeatSelector"]) withObject:[request.userInfo objectForKey:@"argument1"] withObject:[request.userInfo objectForKey:@"argument2"]];
} else if ([request.userInfo objectForKey:@"argument1"]) {
[self performSelector:NSSelectorFromString([request.userInfo objectForKey:@"repeatSelector"]) withObject:[request.userInfo objectForKey:@"argument1"]];
} else {
[self performSelector:NSSelectorFromString([request.userInfo objectForKey:@"repeatSelector"])];
}
numberOfFails++;
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Problem" message:@"There was a problem connecting to the servers. Please make sure you have an Internet connection." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
numberOfFails = 0;
}
}
另外,我认为static int numberOfFails 应该是static NSUInteger numberOfFails。而且,我注意到请求以startAsynchronous 开头。 static int numberOfFails 是原子的吗?这可能就是我们收到错误SEGV_ACCERR(映射对象的权限无效)的原因。
想法?
【问题讨论】:
标签: iphone objective-c ios crash segmentation-fault