我已将此请求放在ViewDidLoad
中,但即使我有一个良好的互联网连接,它仍会弹出UIAlertView
不停止并且没有返回任何值。我需要延长超时时间吗?
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:URL];
__unsafe_unretained ASIFormDataRequest *_request = request;
[request setRequestMethod:@"POST"];
[request setPostValue:@"admin_request_user_join_group" forKey:@"tag"];
[request setPostValue:groupID forKey:@"group_id"];
[request setPostValue:userID forKey:@"poster_user_id"];
[request setPostValue:targetUserID forKey:@"target_user_id"];
[request setDelegate:self];
[request setTimeOutSeconds:30.0];
[request setShouldAttemptPersistentConnection:NO];
[request startAsynchronous];
[request setCompletionBlock:^(void){
NSInteger responseCode = [_request responseStatusCode];
if (responseCode == 200 || responseCode == 201 || responseCode == 202)
{
NSMutableDictionary *response = (NSMutableDictionary *)[[_request responseString] JSONValue];
NSInteger success = [[response objectForKey:@"success"] integerValue];
if (success == 1) {
NSMutableDictionary *dict = [myFriendArray objectAtIndex:sender.tag];
[dict setObject:@"0" forKey:@"join_group_status"];
[myFriendArray replaceObjectAtIndex:sender.tag withObject:dict];
NSIndexPath *rowToReload = [NSIndexPath indexPathForRow:sender.tag inSection:0];
NSArray* rowsToReload = [NSArray arrayWithObjects:rowToReload, nil];
}
}
}];
[request setFailedBlock:^(void){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Failed" message:[NSString stringWithFormat:NSLocalizedString(@"CONNECTION_FAILED", nil)] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
}];
答案 0 :(得分:0)
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:URL];
__unsafe_unretained ASIFormDataRequest *_request = request;
[request setRequestMethod:@"POST"];
[request setPostValue:@"admin_request_user_join_group" forKey:@"tag"];
[request setPostValue:groupID forKey:@"group_id"];
[request setPostValue:userID forKey:@"poster_user_id"];
[request setPostValue:targetUserID forKey:@"target_user_id"];
[request setDelegate:self];
[request setTimeOutSeconds:30.0];
[request setShouldAttemptPersistentConnection:NO];
[request startAsynchronous];
[request setCompletionBlock:^(void){
NSInteger responseCode = [_request responseStatusCode];
if (responseCode == 200 || responseCode == 201 || responseCode == 202)
{
NSMutableDictionary *response = (NSMutableDictionary *)[[_request responseString] JSONValue];
NSInteger success = [[response objectForKey:@"success"] integerValue];
if (success == 1) {
NSMutableDictionary *dict = [myFriendArray objectAtIndex:sender.tag];
[dict setObject:@"0" forKey:@"join_group_status"];
[myFriendArray replaceObjectAtIndex:sender.tag withObject:dict];
NSIndexPath *rowToReload = [NSIndexPath indexPathForRow:sender.tag inSection:0];
NSArray* rowsToReload = [NSArray arrayWithObjects:rowToReload, nil];
}
}
[request setFailedBlock:^(void){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Failed" message:[NSString stringWithFormat:NSLocalizedString(@"CONNECTION_FAILED", nil)] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
}];
}];
这可能对您有所帮助