swift - 不具有 GroupContainerIdentifier 的持久性 HTTPCookieStorage
问题描述
我设置了一个HTTPCookieStorage
这样的:
let storage = HTTPCookieStorage.sharedCookieStorage(forGroupContainerIdentifier: "user100")
storage.cookieAcceptPolicy = .always
let cookieProperties: [HTTPCookiePropertyKey : Any] = [.name : "example\(Date().timeIntervalSince1970)",
.value : "value\(Date().timeIntervalSince1970)",
.domain : "www.example\([100,200,300].randomElement()!).com",
.originURL : "www.example.com",
.path : "/",
.version : "0",
.expires : Date().addingTimeInterval(2629743)
]
storage.setCookie(HTTPCookie(properties: cookieProperties)!)
我发现这样做HTTPCookieStorage.shared
实际上可以保存 cookie,但这种习惯HTTPCookieStorage
不是。如何让它持久化?
解决方案
这是我的发现,forGroupContainerIdentifier
cookie 的目的是在您的应用程序之间共享 cookie。就像在一个应用程序中创建一个用于 cookie 存储的组,而在另一个应用程序中,您希望访问该组,因此为此您需要选择正确的组名称。您需要在应用程序门户开发人员站点上创建组,并且需要将该组添加到您的两个应用程序包 ID 中。之后,您将能够使用这些 cookie。有关更多信息,请查看此线程。Cookie 存储
推荐阅读
- sql - 显示不同模式的所有表
- xamarin.android - InputFilter 行为不正确
- prometheus - 如何为所有指标添加额外标签
- r - 如何遍历循环
- distributed-computing - 将 Chapel 1.19 与 GASNet PSM (OmniPath) 基板一起使用时的问题
- python - 创建一个 Python 模块,其依赖项自包含
- python - 有和没有@tf.function 的不同行为
- mysql - 如何在 JPQL 选择查询中从新创建的对象中按值排序实体?
- azure - OpenLiberty Docker 映像示例应用程序无法正常工作
- entity-framework-core - 更改实体框架核心代码先迁移名称格式