【问题标题】:Not persistent HTTPCookieStorage with GroupContainerIdentifier不具有 GroupContainerIdentifier 的持久性 HTTPCookieStorage
【发布时间】:2019-12-12 04:06:14
【问题描述】:

我这样设置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 不是。如何让它持久化?

【问题讨论】:

    标签: swift uikit httpcookie nshttpcookiestorage


    【解决方案1】:

    这是我的发现,forGroupContainerIdentifier cookie 的目的是在您的应用程序之间共享 cookie。就像在一个应用程序中创建一个用于 cookie 存储的组,而在另一个应用程序中,您希望访问该组,因此为此您需要选择正确的组名称。您需要在应用程序门户开发人员站点上创建组,并且需要将该组添加到您的两个应用程序包 ID 中。之后,您将能够使用这些 cookie。有关更多信息,请查看此线程。 Cookies storage

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-10
      • 2021-07-14
      • 1970-01-01
      • 1970-01-01
      • 2020-12-28
      相关资源
      最近更新 更多