RestKit: What delegate method is called for postObject?

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.

  • When to use restoreCompletedTransactions for in-app purchases?
  • how to use rounded corner label in iphone,UILabel Round Corners
  • Using Huffman coding to compress images taken by the iPhone camera
  • A dynamic method name (Objective-C)
  • View appear with modal view animation instead of show (push) animation
  • Objective-C - Disadvantages to Bridging With C++?
  • 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’.}

    3 Solutions Collect From Internet About “RestKit: What delegate method is called for postObject?”

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


        - (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error;

    Once you have setup your mappings correctly the posting of objects is very easy. Like Paul Cezanne pointed out, the corresponding callbacks will be used.

    For posting objects, however, you’ll also need a serialisation mapping that tells the framework which parameters should be converted to POST parameters:

    Mapping Example:

        // Serialisation Mapping
        RKObjectMapping *messageSendMapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
        [messageSendMapping mapAttributes:@"name", @"number", @"text", nil];
        [[RKObjectManager sharedManager].mappingProvider
                               forClass:[Message class]];

    Update: For trouble shooting purposes you might want to increase the log level for RestKit like so:

    RKLogConfigureByName("RestKit", RKLogLevelTrace);
    RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);
    RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
    RKLogConfigureByName("RestKit/CoreData", RKLogLevelTrace);

    Make sure that RKObjectManager has been initialized:

    NSString *url = @"";
    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"];