【发布时间】:2014-02-26 06:01:28
【问题描述】:
我正在UIBackgroundTaskIdentifier 下运行某个任务,因为我想在后台运行它。我的代码看起来像这样。
-(void) function
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
UIBackgroundTaskIdentifier BGIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{}];
// some processing
dispatch_async(dispatch_get_main_queue(), ^{
// some UI stuff
});
// some processing again
dispatch_async(dispatch_get_main_queue(), ^{
// some UI stuff again
});
[[UIApplication sharedApplication] endBackgroundTask:BGIdentifier];
});
}
所以我有两个问题。
- 如果我的应用程序在某些处理过程中进入后台,对主队列的 dispatch_async 调用会发生什么情况?
- 这是一个好的设计吗?
【问题讨论】:
-
感谢 Rob 指出这一点。我已经编辑了问题。
标签: objective-c objective-c-blocks grand-central-dispatch uibackgroundtask