我已经尝试了网上的各种样本(最后一个是
this one),以便更好地理解NSUrlSession.
解决方法
如果系统终止您的应用并且您的后台会话具有有效下载,则您的下载将继续,系统将在下载完成后启动您的应用.但是,如果用户强制退出您的应用,则会取消所有任务.
Documentation for backgroundSessionConfigurationWithIdentifier:
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.