我需要在后台将视频发布到服务器。到目前为止,我在POST时一直使用这种模式:
- (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。如何使用对象映射在后台发布数据?
答案 0 :(得分:2)
愚蠢的我... RKObjectLoader是RKRequest的子类,所以我可以做loader.backgroundPolicy = ...: - )