AFNetworking没有成功和错误

时间:2013-03-07 00:06:36

标签: ios afnetworking put

我正在尝试将png图像和一些参数上传到我的rails服务器和 我在http://nsscreencast.com/episodes/31-posting-multi-part-forms-with-afnetworking

中关注此示例

我的代码段在

之下

当代码运行时,我看到进度从0到95..98%(看起来它没有完成)..它永远不会碰到我的rails控制器。它会冻结我的IOS应用程序......任何想法为什么它会冻结我的应用程序?我究竟做错了什么?谢谢,欢迎/赞赏任何意见或建议。

NSData *imageData = UIImagePNGRepresentation(image);

NSDictionary *params = @{
                         @"latte[location]" : @"value1",
                         @"latte[submitted_by]" : @"value2",
                         @"latte[comments]" : @"value3"
                         };

NSURLRequest *putRequest = [[MApiClient sharedInstance] multipartFormRequestWithMethod:@"PUT"
                                                                                  path:@"somepath.json"
                                                                            parameters:params
                                                             constructingBodyWithBlock:^(id formData) {
                                                                 [formData appendPartWithFileData:imageData
                                                                                             name:@"latte[photo]"
                                                                                         fileName:@"latte.png"
                                                                                         mimeType:@"image/png"];
                                                             }];

AFHTTPRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:putRequest];
[operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
    NSLog(@"%f", (totalBytesWritten / (float) totalBytesExpectedToWrite));

}];



[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    if (operation.response.statusCode == 200 || operation.response.statusCode == 201) {
        NSLog(@"whats here, %@", responseObject);
    } else {
        NSLog(@"whats here, %@", responseObject);
    }
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"whats here, %@", error);

}];

[[MyApiClient sharedInstance] enqueueHTTPRequestOperation:operation];

1 个答案:

答案 0 :(得分:0)

我会分析你的项目,它可能会抛出一些块变量的问题。