本文介绍了beginBackgroundTaskWithExpirationHandler的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在做一个应用程序,音频将在后台播放。在下面的代码中,bgTask是未声明的。 bgTask是什么类型的对象?
I am making an application where audio will play in the background. In the following code, bgTask is undeclared. What kind of object should bgTask be?
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{});
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}
推荐答案
您需要声明bgTask您分配:
You need to declare bgTask before you assign:
UIBackgroundTaskIdentifier bgTask = 0;
这篇关于beginBackgroundTaskWithExpirationHandler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!