postOperationでtargetObjectを設定する方法がわかりません。現在、すべてのpostObjectメソッドは正常に機能しており、サーバーからオブジェクトに応答データをマッピングしています。ただし、managedObjectRequestOperationWithRequestはそれを行わず、targetObjectのログはnullを返します。
手動で設定しようとしましたが(以下のコードコメントを参照)、管理対象オブジェクトのコンテキストが一致しない(1つがnull)というエラーが返されます。これは糸脱毛のせいですか?とにかくこれの周り?
// post image
// create request
postRequest = [RKObjectManager.sharedManager multipartFormRequestWithObject:media method:RKRequestMethodPOST path:path parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:media.imageData name:@"userfile[]" fileName:filename mimeType:@"image/jpeg"];
}];
// create operation
RKManagedObjectRequestOperation *postOperation = [RKObjectManager.sharedManager managedObjectRequestOperationWithRequest:postRequest managedObjectContext:viewController.managedObjectContext success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(@"operation.targetObject: %@", operation.targetObject);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"post image error: %@", error);
}];
// postOperation.targetObject = media;
// enqueue operation
[RKObjectManager.sharedManager enqueueObjectRequestOperation:postOperation];
// monitor upload progress
[postOperation.HTTPRequestOperation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
NSLog(@"bytesWritten: %d, totalBytesWritten: %lld, totalBytesExpectedToWrite: %lld", bytesWritten, totalBytesWritten, totalBytesExpectedToWrite);
}];
これは、postOperation.targetObject=media;をコメントアウトしたときに受け取るエラーです。
2012-12-14 20:04:36.256 Keepsayk Alpha[1966:1503] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Serious Core Data error: requested existing object with ID 0x1f805a30 <x-coredata:///Media/t0FEC53CF-F383-4E7E-8568-38F42EA839453> in context <NSManagedObjectContext: 0x1fa9a790>, instead got an object reference in context (null). This may indicate that the objectID for your target managed object was obtained using `obtainPermanentIDsForObjects:error:` in the wrong context.'