gpt4 book ai didi

ios - 我们是否应该为所有不同的可下载文件创建不同的唯一 session 标识符 - swift

转载 作者:可可西里 更新时间:2023-11-01 01:57:34 25 4
gpt4 key购买 nike

我是IOS编程新手。我想创建一个示例应用程序,允许用户从我的服务器下载许多文件。例如,我有 10 个文件,那么我是否应该调用方法 let configuration = URLSessionConfiguration.background(withIdentifier: "firstTask") 10 次,但标识符与第一个文件 withIdentifier: "firstTask"不同 和第二个文件应该是 withIdentifier: "secondTask"?。原因是我想让用户下载相同的文件名,然后我只用其他名称修改 withIdentifier: "" 。那正确吗?请给我一些建议。

其他问题:

我们如何使具有特定标识符的 session 无效?

最佳答案

根据documentation :

identifier The unique identifier for the configuration object. This parameter must not be nil or an empty string.

还有一个说法:

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 to 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.

Finally :

Create a background URLSessionConfiguration object with the class method background(withIdentifier:) of URLSession, providing a session identifier that is unique within your app. Because most apps need only a few background sessions (usually one), you can use a fixed string for the identifier, rather than a dynamically generated identifier. The identifier doesn’t need to be unique globally.

因此,为您的应用程序使用一个唯一的标识符 是合理的。例如,它可能包含包 ID,例如整个应用的 com.awesomeapps.appname.sessionId

关于ios - 我们是否应该为所有不同的可下载文件创建不同的唯一 session 标识符 - swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50585840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com