当应用程序进入后台状态时,我正在做一些处理,我把它放在beginBackgroundTaskWithExpirationHandler()下,因此应该分配十分钟。但是,我相信该应用程序在此之前已被暂停。我正在执行的任务是内存和 CPU 密集型的,那么操作系统是否有可能将我的应用程序置于挂起状态?
如果是这样,有没有办法绕过这些限制。(我愿意使用私有 API)。
下面是启动后台任务的代码:
   if([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]){
        if([[UIDevice currentDevice] isMultitaskingSupported]){
            __block UIBackgroundTaskIdentifier bgTask;
            UIApplication *application = [UIApplication sharedApplication];
            bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
                    [application endBackgroundTask:bgTask];
                    bgTask = UIBackgroundTaskInvalid;
            }];
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                [self captureImage];
                [application endBackgroundTask:bgTask];
                bgTask = UIBackgroundTaskInvalid;
            });
        }
    }