ARC问题:没有已知的选择器实例方法'appendPartWithFileData:mimeType:name:'

时间:2012-03-16 09:05:42

标签: objective-c ios automatic-ref-counting afnetworking

按照AFNetworking示例上传表单时:

NSURL *url = [NSURL URLWithString:@"https://www.example.com/"];
AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:url];

NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                        keyField.text, @"key",
                        valField.text, @"val",
                        nil];

NSData *imageData = UIImagePNGRepresentation(image);

NSURLRequest *request = [client multipartFormRequestWithMethod:@"POST" 
                                                          path:@"/upload" 
                                                    parameters:params 
                                     constructingBodyWithBlock: ^(id <AFMultipartFormData> formData) {
                                         [formData appendPartWithFileData:imageData 
                                                                 mimeType:@"image/png" 
                                                                     name:@"avatar"];
                                     }];

编译返回错误:

ARC Issue: No known instance method for selector 'appendPartWithFileData:mimeType:name:'

我该如何解决?

2 个答案:

答案 0 :(得分:1)

编译器认为这是一个“ARC问题”,这有点奇怪。恕我直言,AFMultipartFormData协议不包含名为appendPartWithFileData:mimeType:name:的方法。看看文档,也许协议被重构,方法签名有点变化。我不确定AFMultipartFormData来自哪里,但是短搜索给了我these docs,表明您可能会appendPartWithFileData:name:fileName:mimeType:取得成功。

答案 1 :(得分:1)

我的AFHTTPClient.h中的签名如下所示:

- (void)appendPartWithFileData:name:fileName:mimeType:

并匹配文档here。可能就是样本已经过时了。

更新:请参阅此SO answer: How do you upload multiple files with AFNetworking