Apple给出thisofbackgroundexecution:-(void)applicationDidEnterBackground:(UIApplication*)application{bgTask=[applicationbeginBackgroundTaskWithName:@"MyTask"expirationHandler:^{//Cleanupanyunfinishedtaskbusinessbymarkingwhereyou//stoppedorendingthetaskoutright.[applicationendBackgroundTask:bgTask];
我有一些长时间运行的进程,即使应用程序进入后台我也想运行。我正在调用应用程序的beginBackgroundTaskWithExpirationHandler:方法,并在expirationBlock中调用应用程序的endBackgroundTask。这是实现:__blockUIBackgroundTaskIdentifiertask=[[UIApplicationsharedApplication]beginBackgroundTaskWithExpirationHandler:^{[[UIApplicationsharedApplication]endBackgroundTask:
我正在尝试在我的应用程序中执行有限长度后台任务。但是,截至目前,我的代码在应用程序暂停之前没有执行。我遵循了相当多的教程,这些教程声称以下内容是正确的,但显然我弄错了。相关代码应发布在下面(如果我遗漏了什么,请要求任何澄清):classManager{privatevarbackgroundTask:UIBackgroundTaskIdentifier=UIBackgroundTaskInvalidinit(){//AddobserverableofdetectingwhenappwillgotobackgroundNotificationCenter.default.addObser