0

我的 viewController 有以下方法,在通过 UIImagePickerController 选择图像后调用该方法。我想将所选图像上传到我的网络服务,但是,当尝试遵循 RestKit 提供的示例时,我收到以下错误:

'RKObjectManager' 没有可见的@interface 声明选择器'multipartFormRequestForObject:method:path:parameters:constructingBodyWithBlock:'

我正在使用最新版本的 restkit,然后右键单击到定义以检查似乎正确的签名。

值得注意的是 AFMultipartFormData 在 XCode 中没有突出显示。我尝试包括#import AFNetworking/AFHTTPClient.h,但它仍然显示为纯文本,我怀疑这可能是问题所在?

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [imageView setImage:image];

    ImageRecord *imageRecord = [ImageRecord new];
    NSDictionary *params = @{@"param1" : @"value1",
                             @"param2" : @"value2",
                             @"param3" : @"value3"};

    // Serialize the Article attributes then attach a file
    NSMutableURLRequest *request = [[RKObjectManager sharedManager] multipartFormRequestForObject:imageRecord method:RKRequestMethodPOST path:@"stuff" parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFileData:UIImagePNGRepresentation(image)
                                    name:@"article[image]"
                                fileName:@"photo.png"
                                mimeType:@"image/png"];
    }];

    RKObjectRequestOperation *operation = [[RKObjectManager sharedManager] objectRequestOperationWithRequest:request success:nil failure:nil];
    [[RKObjectManager sharedManager] enqueueObjectRequestOperation:operation]; // NOTE: Must be enqueued rather than started


    [self dismissViewControllerAnimated:YES completion:NULL];
}

感谢您的任何指点!

4

1 回答 1

1

该方法是multipartFormRequestWithObject:(请注意,您使用的方法名称有ForObject)。您不需要导入任何其他标题。

于 2013-07-29T18:21:49.670 回答