Tag: 公约

在iOS中处理后台任务的正确方法是什么?

我有一个VoIP应用程序,它需要在后台运行。 据我的理解,这些是我需要做的事情: 将该应用标记为voip。 将“应用程序不在后台运行”标志设置为NO。 设置一个到期处理程序,一段延长标准10分钟执行时间的代码。 更多? 我在info.plist文件中设置了两个标志,我得到了10分钟的时间。 我尝试了这篇文章中的build议。 这是我的代码: //in didFinishLaunchingWithOptions: expirationHandler = ^{ NSLog(@"ending background task"); [[UIApplication sharedApplication] endBackgroundTask:bgTask]; NSLog(@"restarting background task"); bgTask = UIBackgroundTaskInvalid; bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:expirationHandler]; NSLog(@"finished running background task"); }; //in applicationDidEnterBackground NSLog(@"entering background mode"); bgTask = UIBackgroundTaskInvalid; bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:expirationHandler]; // Start the long-running task and […]