2

What method of RKObjectLoaderDelegate gets called after the method - (RKObjectLoader *)postObject:(id<NSObject>)object delegate:(id<RKObjectLoaderDelegate>)delegate is called?

I'm trying to run some more code once my POST is successful.

EDIT (more info):

Neither of the methods that @Paul mentions are being called, but my server is interpreting the POST somewhat correctly because the DB is being written to.

During app initialization, I am doing the following:

// Grab the reference to the router from the manager
RKObjectRouter *router = [RKObjectManager sharedManager].router;

// Define a default resource path for all unspecified HTTP verbs
[router routeClass:[EventMessage class] toResourcePath:@"/events_messages/:idPrimaryKey"];
[router routeClass:[EventMessage class] toResourcePath:@"/event_messages" forMethod:RKRequestMethodPOST];

And when I am ready to POST, I am doing this:

RKObjectMapping *objectMapping = [RKObjectMapping mappingForClass:[EventMessage class]];
[objectMapping mapKeyPath:@"user_id" toAttribute:@"userId"];
[objectMapping mapKeyPath:@"event_id" toAttribute:@"eventId"];
[objectMapping mapKeyPath:@"message" toAttribute:@"message"];

[[RKObjectManager sharedManager].mappingProvider registerMapping:objectMapping withRootKeyPath:@"event_message"];

[[RKObjectManager sharedManager] postObject:eventMessage delegate:self];

And this is the error that I get in the console:

Error Domain=JKErrorDomain Code=-1 "Unexpected token, wanted '{', '}', '[', ']', ',', ':', 'true', 'false', 'null', '"STRING"', 'NUMBER'." UserInfo=0x7b9f510 {JKAtIndexKey=0, JKLineNumberKey=1, NSLocalizedDescription=Unexpected token, wanted '{', '}', '[', ']', ',', ':', 'true', 'false', 'null', '"STRING"', 'NUMBER'.}

4

3 に答える 3

2
    - (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects;

また

    - (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error;
于 2012-04-25T09:02:42.763 に答える
2

マッピングを正しく設定すると、オブジェクトの投稿は非常に簡単になります。Paul Cezanneが指摘したように、対応するコールバックが使用されます。

ただし、オブジェクトを投稿する場合は、どのパラメーターをPOSTパラメーターに変換する必要があるかをフレームワークに指示するシリアル化マッピングも必要です。

マッピング例:

    // Serialisation Mapping
    RKObjectMapping *messageSendMapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];

    [messageSendMapping mapAttributes:@"name", @"number", @"text", nil];

    [[RKObjectManager sharedManager].mappingProvider
            setSerializationMapping:messageSendMapping
                           forClass:[Message class]];

更新:トラブルシューティングの目的で、RestKitのログレベルを次のように増やすことができます。

RKLogConfigureByName("RestKit", RKLogLevelTrace);
RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
RKLogConfigureByName("RestKit/CoreData", RKLogLevelTrace);
于 2012-04-25T09:07:57.697 に答える
0

Make sure that RKObjectManager has been initialized:

NSString *url = @"http://example.com";
RKObjectManager* mgr = [RKObjectManager managerWithBaseURLString:url];

I wasted a bunch of time before noticing that sharedManager is not really a singleton, you have to initialize it.

After that you can use the sharedManager and get an reference to the first one created:

[[RKObjectManager sharedManager].mappingProvider setObjectMapping:mapping forResourcePathPattern:@"/RKKeyValueMappingExample"];
于 2012-06-28T04:09:56.947 に答える