【发布时间】:2013-12-15 19:18:52
【问题描述】:
当客户端收到推送通知时,我会运行一些冗长的同步任务。如果 2 个通知到达太快,我会在同步任务之间发生冲突,因为两者都尝试枚举和更改 coredata。
如何保留对队列的引用并将下一个同步任务分派到同一个队列?对这个问题表示歉意,但我的普通 C 语言不好。谢谢。
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
// I would need to keep reference to 'queue' so I can dispatch to it again with next push notification
dispatch_async(queue, ^{
[self.connection synchronizeWithLocal];
dispatch_async(dispatch_get_main_queue(), ^{
// make UI updates
});
});
}
【问题讨论】:
标签: ios multithreading core-data queue grand-central-dispatch