2013-07-29 23 views
0

我的viewController具有以下方法,在通過UIImagePickerController選擇圖像後調用該方法。我想將選定的圖像上傳到我的Web服務,但是,當試圖關注RestKit提供的示例時,出現以下錯誤:Restkit multipartFormRequestForObject示例不爲我構建

'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

該方法是multipartFormRequestWithObject:(請注意,您使用的方法名稱有ForObject)。你不需要導入任何額外的頭文件。

+0

你搖滾!我複製粘貼來自RestKit的github的代碼,所以我從來沒有懷疑過這樣的事情。謝謝你爲我節省了大量的時間。 – Justin