我想问一下 AFNetworking 库是否在由于连接丢失而无法完成 http 操作的自动恢复时提供某种支持。
举个例子,我想排队更多的http post操作,每一个都用来上传一张图片:如何管理连接丢失的情况(我想知道是否有任何代码会重新启动未完成连接可用时操作)?
NSURL *remoteUrl = [NSURL URLWithString:UPLOAD_SERVER_URL];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:remoteUrl];
[httpClient setParameterEncoding: AFJSONParameterEncoding];
[httpClient setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
NSLog(@"Conenction lost...");
}];
NSMutableURLRequest *afRequest = [httpClient multipartFormRequestWithMethod:@"POST"
path:@"/upload/"
parameters:[photoBean asDictWithoutImageData]
constructingBodyWithBlock:^(id <AFMultipartFormData>formData)
{
[[photoBean asDict] enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) {
if ([key isEqualToString:@"media"])
{
[formData appendPartWithFileData: obj name:@"media" fileName:photoBean._imageFile mimeType:@"image/jpeg"];
}
}];
}
];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:afRequest];
[operation setCompletionBlock:^{
NSLog(@"%@", operation.responseString); //Gives a very scary warning
}];
[operation start];
谢谢!