iOS 13 后台杀死应用问题

3
如何解决这个问题: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

我猜这是因为你试图调用bgTask

[application endBackgroundTask:bgTask];

并将其更改

bgTask = UIBackgroundTaskInvalid;

在它的定义内部。

尝试将其分为两个不同的操作 - bgTask定义和bgTask调用和更改。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接