我的实体用户有一个objectMapping

RKObjectMapping* userMapping = [RKObjectMapping mappingForClass:[User class]];
[userMapping mapKeyPath:@"first_name" toAttribute:@"firstName"];
[userMapping mapKeyPath:@"last_name" toAttribute:@"lastName"];
[manager.mappingProvider setMapping:userMapping forKeyPath:@"users"];
[manager.mappingProvider setSerializationMapping:[userMapping inverseMapping] forClass:[User class]];

当应用程序进入后台时,我想保存他的个人资料:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [[RKObjectManager sharedManager] putObject:currentUser delegate:self];
}

但这不会让我在关闭应用程序时运行请求(我猜不允许有新线程)。因此,我想同步执行此操作。

但是,我没有使用RestKit做到这一点。我这边有误会吗?我想拥有:
[[RKObjectManager sharedManager] putObjectSynchronously:currentUser];

最佳答案

如果需要同步发送,您将无法在RKObjectManager上使用便捷方法,例如putObject,因为这些便捷方法都代表您异步发送请求。相反,您可以尝试以下操作:

RKObjectLoader* loader = [[RKObjectManager sharedManager] objectLoaderForObject:currentUser method:RKRequestMethodPUT delegate:nil];
RKResponse* response = [loader sendSynchronously];

10-07 17:30