" EXC_BAD_ACCESS"尝试使用NSURLSessionUploadTask使用AFNetworking多部分上传时

时间:2015-10-13 20:38:42

标签: ios afnetworking afnetworking-2

我正在使用 NSURLSessionUploadTask ,使用 AFNetworking 多部分请求将mp3文件上传到我们的服务器。

我正在使用AFNetworking示例中的代码。

NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:@"http://example.com/upload" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFileURL:[NSURL fileURLWithPath:@"file://path/to/image.jpg"] name:@"file" fileName:@"filename.jpg" mimeType:@"image/jpeg" error:nil];
    } error:nil];

AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSProgress *progress = nil;

NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
    if (error) {
        NSLog(@"Error: %@", error);
    } else {
        NSLog(@"%@ %@", response, responseObject);
    }
}];

[uploadTask resume];

这样做时,应用程序会获得&#34; EXC_BAD_ACCESS&#34;抛出&#34; _CFStreamSetDispatchQueue&#34; 。在应用程序通过 needNewBodyStream 委托方法后,似乎会抛出此错误。

有没有人经历过这个?

"EXC_BAD_ACCESS" thrown in the "_CFStreamSetDispatchQueue" enter image description here

0 个答案:

没有答案
相关问题