Restkit multipartFormRequestForObject示例不适合我

时间:2013-07-29 17:47:22

标签: restkit afnetworking restkit-0.20

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

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

我正在使用最新版本的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];
}

感谢您的任何指示!

1 个答案:

答案 0 :(得分:1)

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