2

我需要在后台将视频发布到服务器。到目前为止,我在发布时一直在使用这种模式:

- (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;
}

...但是这种模式似乎不允许我访问任何设置 backgroundPolicy 的 RKRequest 对象。所以,我看过像这样使用 RKClient :

- (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;
}

...但 RKRequest 对象似乎没有访问设置映射的 RKObjectLoader 的方法。如何使用对象映射在后台发布数据?

4

1 回答 1

2

愚蠢的我...... RKObjectLoader 是 RKRequest 的子类,所以我可以做 loader.backgroundPolicy = ... :-)

于 2012-07-31T23:17:17.137 回答