ios - 在后台模式下关闭我的应用程序后将下载简历

标签 ios swift

我发现可以在应用程序的后台模式下下载。我已经在 XCode 中实现了后台获取模式并注册了后台任务并且它工作正常。

是否可以在用户强制关闭我的应用程序后恢复下载任务?怎么办?

最佳答案

不,当您的应用程序被用户终止时,您不能继续下载!您的应用程序必须要求保持在后台状态!!!因为如果用户强制关闭应用程序,这意味着他不想再运行它了。如果您的应用程序被系统暂停,那么它可以被唤醒,但如果它被用户终止则不能!

If an iOS app is terminated by the system and relaunched, the app can use the same identifier to create a new configuration object and session and retrieve the status of transfers that were in progress at the time of termination. This behavior applies only for normal termination of the app by the system. If the user terminates the app from the multitasking screen, the system cancels all of the session’s background transfers. In addition, the system does not automatically relaunch apps that were force quit by the user. The user must explicitly relaunch the app before transfers can begin again.

更新:(如评论中所述)

Refer the apple documentation , 它指出,

This method lets your app know that it is about to be terminated and purged from memory entirely. You should use this method to perform any final clean-up tasks for your app, such as freeing shared resources, saving user data, and invalidating timers. Your implementation of this method has approximately five seconds to perform any tasks and return. If the method does not return before time expires, the system may kill the process altogether.

For apps that do not support background execution or are linked against iOS 3.x or earlier, this method is always called when the user quits the app. For apps that support background execution, this method is generally not called when the user quits the app because the app simply moves to the background in that case. However, this method may be called in situations where the app is running in the background (not suspended) and the system needs to terminate it for some reason.

After calling this method, the app also posts a UIApplicationWillTerminate notification to give interested objects a chance to respond to the transition.

关于ios - 在后台模式下关闭我的应用程序后将下载简历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41379493/

相关文章:

ios - 如何在 AsyncDisplayKit 中使用 scrollView 函数

ios - 如何使用 heightForRowAtIndexPath 方法?

ios - 关于在 Swift 中比较数组值后移动索引值的问题

ios - 委托(delegate)仍然为零

ios - 为什么在 beginUpdates 和 endUpdates 中使用 reloadRows

ios - 升级到 Swift 2.0 导致 NSCODER 出错

ios - 自 Xcode 10 起,UIImageView setImage 在后台线程上崩溃

ios - 一旦在 Swift 中达到最大高度,UITextView 就会变得可滚动

ios - UINavigationBar 在 AppDelegate.swift 中设置自定义阴影

ios - 如何清除 UIImagePickerController 的背景?