John Michael Zorko
John Michael Zorko

Reputation: 329

RestKit: per-request object mapping when using [[RKClient sharedClient] post: usingBlock:]

I need to POST a video to a server in the background. Until now i've been using this sort of pattern when POSTing:

- (BOOL)loginUser:(user *)user
{
    BOOL ret = NO;

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [appDelegate.waitView startWithMessage:@"Signing in ..."];

    [self.objectManager postObject:user usingBlock:^(RKObjectLoader *loader)
     {
         loader.delegate = self;
         loader.targetObject = nil;

         loader.objectMapping = [RKObjectMapping mappingForClass:[user class] usingBlock:^(RKObjectMapping *mapping)
                             {
                                 [mapping mapKeyPath:@"id" toAttribute:@"ID"];
                                 [mapping mapKeyPath:@"last_name" toAttribute:@"last_name"];
                                 [mapping mapKeyPath:@"first_name" toAttribute:@"first_name"];
                                 [mapping mapKeyPath:@"middle_name" toAttribute:@"middle_name"];
                                 [mapping mapKeyPath:@"email" toAttribute:@"email"];
                                 [mapping mapKeyPath:@"password" toAttribute:@"password"];
                                 [mapping mapKeyPath:@"authentication_token" toAttribute:@"authentication_token"];
                             }];

         loader.serializationMapping = [loader.objectMapping inverseMapping];
         loader.serializationMapping.rootKeyPath = NSStringFromClass([user class]);
     }];

    return ret;
}

... but this pattern doesn't seem to let me access any RKRequest object on which to set the backgroundPolicy. So, i've looked at using RKClient like so:

- (BOOL)postBigMediaFile:(NSString *)pathToBigFile
{
    BOOL ret = NO;

    NSString *resourcePath = @"/bigFile";

    [[RKClient sharedClient] post:resourcePath usingBlock:^(RKRequest *request)
     {
         request.backgroundPolicy = RKRequestBackgroundPolicyContinue;

         // how do I set up the object mapping?


     }];

    return ret;
}

... but the RKRequest object doesn't seem to have a way of accessing an RKObjectLoader for which to setup the mapping on. How do I post data in the background using object mapping?

Upvotes: 2

Views: 540

Answers (1)

John Michael Zorko
John Michael Zorko

Reputation: 329

Silly me ... RKObjectLoader is a subclass of RKRequest, so I can just do loader.backgroundPolicy = ... :-)

Upvotes: 2

Related Questions