您如何解决此问题:在应用程序进入后台后,IOS 13不断杀死该应用程序实例。

UIApplication *application = [UIApplication performSelector:@selector(sharedApplication)];
__block UIBackgroundTaskIdentifier bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
    // Clean up any unfinished task business by marking where you
    // stopped or ending the task outright.
    [application endBackgroundTask:bgTask];
    bgTask = UIBackgroundTaskInvalid;
}];

// Start the long-running task and return immediately.
[self deleteOldFilesWithCompletionBlock:^{
    [application endBackgroundTask:bgTask];
    bgTask = UIBackgroundTaskInvalid;
}];

最佳答案

我想这是因为您正在尝试调用bgTask

[application endBackgroundTask:bgTask];

并更改它
bgTask = UIBackgroundTaskInvalid;

在其定义内。

尝试将其分开进行2种不同的操作-bgTask定义以及bgTask调用和更改。

关于ios - iOS 13背景杀死,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59371629/

10-11 19:00