Hi can I run a download task for infinite time (say for 1hr) if I use NSUrlsession backgroundSessionConfiguration in ios. Or will it get killed after 3mins?
如果我在ios中使用NSUrlsession backgroundSessionConfiguration,我可以无限期地运行下载任务(例如1小时)。还是会在3分钟后被杀?
1 个解决方案
#1
0
Yes and no. You can set up downloads to run in the background using NSURLSession
(or URLSession
, as it's called in Swift 3.)
是的,不是。您可以使用NSURLSession(或者在Swift 3中调用的URLSession)设置要在后台运行的下载。
It's been a while since I've used this, but here's what I remember:
我用了这个已经有一段时间了,但这是我记得的:
When you do that the system takes over managing your download for you. Your app can be in the foreground, in the background, or not running at all and the download still proceeds. If your app is no longer running when the download completes, your app will be re-launched. You will need to implement the application:handleEventsForBackgroundURLSession:completionHandler:
method in your app delegate. See the docs on that method for instructions on what to do if a download completes when your app is not running.
当您这样做时,系统将为您管理下载。您的应用可能位于前台,后台或根本不运行,下载仍然继续。如果您的应用在下载完成后不再运行,您的应用将会重新启动。您需要在应用程序委托中实现应用程序:handleEventsForBackgroundURLSession:completionHandler:方法。有关如果在您的应用未运行时下载完成后该怎么做的说明,请参阅该方法的文档。
Because the system takes over the job of managing background downloads it doesn't keep your app alive in the background. It follows the same background rules as normal. (It gets suspended quite quickly if the user switches apps, and can be terminated at any time after that.)
由于系统接管了管理后台下载的工作,因此它不会让您的应用程序在后台保持活动状态。它遵循与正常相同的背景规则。 (如果用户切换应用程序,它会很快暂停,并且可以在此之后的任何时间终止。)
#1
0
Yes and no. You can set up downloads to run in the background using NSURLSession
(or URLSession
, as it's called in Swift 3.)
是的,不是。您可以使用NSURLSession(或者在Swift 3中调用的URLSession)设置要在后台运行的下载。
It's been a while since I've used this, but here's what I remember:
我用了这个已经有一段时间了,但这是我记得的:
When you do that the system takes over managing your download for you. Your app can be in the foreground, in the background, or not running at all and the download still proceeds. If your app is no longer running when the download completes, your app will be re-launched. You will need to implement the application:handleEventsForBackgroundURLSession:completionHandler:
method in your app delegate. See the docs on that method for instructions on what to do if a download completes when your app is not running.
当您这样做时,系统将为您管理下载。您的应用可能位于前台,后台或根本不运行,下载仍然继续。如果您的应用在下载完成后不再运行,您的应用将会重新启动。您需要在应用程序委托中实现应用程序:handleEventsForBackgroundURLSession:completionHandler:方法。有关如果在您的应用未运行时下载完成后该怎么做的说明,请参阅该方法的文档。
Because the system takes over the job of managing background downloads it doesn't keep your app alive in the background. It follows the same background rules as normal. (It gets suspended quite quickly if the user switches apps, and can be terminated at any time after that.)
由于系统接管了管理后台下载的工作,因此它不会让您的应用程序在后台保持活动状态。它遵循与正常相同的背景规则。 (如果用户切换应用程序,它会很快暂停,并且可以在此之后的任何时间终止。)