更新xcode后图像上传错误

时间:2014-10-09 09:51:58

标签: ios xcode5 xcode6 afnetworking-2

我正在使用AFNetworking,我正在使用图片上传功能。

它工作得很好。现在我将XCode更新为最新版本。 XCode 6.0.1。之后我更新了所有pods文件。但现在它没有用。我没有改变任何事情。

XCode 5.1和XCode 6.0.1这两个版本我正在使用AFNetworking 2.2.4。

我的代码是

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

                NSString *boundary = @"---------------------------14737809831466499882746641449";
                NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
                [request setValue:contentType               forHTTPHeaderField: @"Content-Type"];
                [request setValue:@"Keep-Alive"             forHTTPHeaderField:@"Connection"];
                [request setValue:@"multipart/form-data"    forHTTPHeaderField:@"ENCTYPE"];
                [request setValue:@"test"                   forHTTPHeaderField:@"uploaded_file"];

                NSError *error = nil;
                request = [self.requestSerializer multipartFormRequestWithMethod:@"POST"
                                                                       URLString:APIURL
                                                                      parameters:nil
                                                       constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
                                                           [formData appendPartWithFileData:horse.imageData
                                                                                       name:@"uploaded_file"
                                                                                   fileName:@"myimage.jpg"
                                                                                   mimeType:@"image/jpeg"];
                                                       }
                                                                           error:&error];


                AFHTTPRequestOperation *operation =
                [self HTTPRequestOperationWithRequest:request
                                              success:^(AFHTTPRequestOperation *operation, id responseObject) {



                                              } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                                  NSLog(@"Failure %@", error.description);
                                              }];

                [operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
                    NSLog(@"Wrote %ld/%ld", (long)totalBytesWritten, (long)totalBytesExpectedToWrite);
                }];

                [operation start];

错误消息

** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -streamStatus only defined for abstract class.  Define -[AFMultipartBodyStream streamStatus]!'
*** First throw call stack:
(0x2d656ecb 0x37df1ce7 0x2d656e0d 0x2e033bcb 0x2e03be35 0x23d4f3 0x2d5ab97b 0x2d25a6cb 0x2d2ea0c7 0x2d242e3d 0x2d259d3f 0x2d2592cb 0x2d2590a7 0x2d29f0d7 0x2d242e3d 0x2d258ac5 0x2d2a8cf7 0x2d2580d9 0x2d257f39 0x2d25622d 0x2d255d51 0x2d2ad1cd 0x2d58a159 0x2d25299b 0x2d252859 0x2d2526e9 0x2d621faf 0x2d621477 0x2d61fc67 0x2d58a729 0x2d58a50b 0x2dfcb241 0x2e040a0f 0x3840d959 0x3840d8cb 0x3840bae8)
libc++abi.dylib: terminating with uncaught exception of type NSException

问题是什么并解释我。

1 个答案:

答案 0 :(得分:1)

我在这里使用旧的AFNetwoking。我将AFNetworking 2.2.4更改为2.4.1。然后它正在工作。 无论如何,谢谢@ n00bProgrammer