问题描述
|
我正在调试崩溃报告为:
Exception Type: SIGSEGV
Exception Codes: SEGV_ACCERR
崩溃发生在执行ѭ1的行上。
该应用程序使用ASIHTTP
。我个人更喜欢使用NSURLConnection
。如果请求失败,我永远不会自动重复对ѭ3的请求,因为我从未见过在不该请求时会失败。我宁愿给UI刷新按钮,还是显示带有按钮的“ 5”以重试一次或类似的操作。
无论如何,为了与其他团队成员合作,我希望在不将ѭ2替换为ѭ3的情况下解决此问题。
该请求正在以类似下面的内容开始:
- (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];
}
我注意到的一件事是,头文件中没有“ 9”,但是此回调方法仍称为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
。而且,我注意到请求始于ѭ13started。 static int numberOfFails
是原子的吗?这就是为什么我们会收到错误“ 15”(映射对象的权限无效)的原因。
有什么想法吗?
解决方法
该问题可能与您的静态变量无关。
requestFailed:
是在主线程还是在后台线程上执行?
如果它在后台线程上,则需要使用performSelectorOnMainThread:withObject:
。
如果它在主线程上,则可能需要在运行循环之前执行一次新的HTTP请求。为此,请使用performSelector:withObject:afterDelay:
,并将\'0.0 \'用作延迟。
您会注意到,这两种方法都只允许使用一个方法参数。通常,您在ѭ19中传递参数,而不是像执行操作那样尝试事先解析出参数数量。