【发布时间】:2015-12-11 12:46:13
【问题描述】:
在我的项目中,我使用 AFNetworking 进行 Api 调用,如何确定 AFNetworking 的默认超时秒数。请提出建议。
【问题讨论】:
-
并且请展示您解决问题的尝试。
-
默认超时秒数:60
标签: ios objective-c afnetworking nsurlconnection nsurl
在我的项目中,我使用 AFNetworking 进行 Api 调用,如何确定 AFNetworking 的默认超时秒数。请提出建议。
【问题讨论】:
标签: ios objective-c afnetworking nsurlconnection nsurl
AFNetwork 的默认超时时间为 60 秒
超时间隔,以秒为单位。如果在连接过程中尝试 请求保持空闲的时间超过超时间隔,请求 被认为已经超时。默认超时间隔为 60 秒。
如果你想减少超时
NSDictionary *params = @{@"par1": @"value1",
@"par2": @"value2"};
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager.requestSerializer setTimeoutInterval:25]; //Time out after 25 seconds
[manager POST:@"URL" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
//Success call back bock
NSLog(@"Request completed with response: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//Failure callback block. This block may be called due to time out or any other failure reason
}];
【讨论】: