AFNetworking在连接丢失后恢复HTTP操作

时间:2012-07-07 19:12:53

标签: http connection afnetworking

我想询问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]; 

谢谢!

0 个答案:

没有答案