iOS 13背景杀死

时间:2019-12-17 09:55:29

标签: ios objective-c

您如何解决此问题:当应用进入后台后,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;
}];

1 个答案:

答案 0 :(得分:0)

我想那是因为您试图调用bgTask

[application endBackgroundTask:bgTask];

并更改

bgTask = UIBackgroundTaskInvalid;

在其定义内。

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