Making synchronous calls with RestKit(使用 RestKit 进行同步调用)
问题描述
我的实体用户有一个 objectMapping
I have an objectMapping for my entity User
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]];
我想在应用程序进入后台时保存他的个人资料:
And I want to save his profile when the application goes background:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[RKObjectManager sharedManager] putObject:currentUser delegate:self];
}
但它不会让我在关闭应用程序时运行请求(我猜不允许新线程).所以我想同步做这个.
But it won't let me run the request while closing down the app (I'm guessing no new threads are allowed). So I would like to do this synchronously.
但是,我没能用 RestKit 做到这一点.我这边是不是有什么误会?我想要:
However, I didn't manage to do this with RestKit. Is there some misunderstanding on my side ? I would like to have:
[[RKObjectManager sharedManager] putObjectSynchronously:currentUser];
推荐答案
如果你需要同步发送,你将无法使用 RKObjectManager 上的便捷方法,比如 putObject,因为这些便捷方法都发送代表您异步请求.相反,您可以尝试以下方法:
If you need to send synchronously, you're not going to be able to use the convenience methods on RKObjectManager, like putObject, because these convenience methods all send the request asynchronously on your behalf. Instead, you can try something like the following:
RKObjectLoader* loader = [[RKObjectManager sharedManager] objectLoaderForObject:currentUser method:RKRequestMethodPUT delegate:nil];
RKResponse* response = [loader sendSynchronously];
这篇关于使用 RestKit 进行同步调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 RestKit 进行同步调用
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01