Not persistent HTTPCookieStorage with GroupContainerIdentifier

500 views Asked by At

I set up a HTTPCookieStorage like this:

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)!)

I found out that doing the same for HTTPCookieStorage.shared actually saves the cookies, this custom HTTPCookieStorage is not. How to make it persistent?

1

There are 1 answers

0
Muhammad Shauket On

Here is my finding, the purpose of forGroupContainerIdentifier cookies is to share cookies across your applications. Like in one app you create one group for cookies storage and in another application, you want to access that group so for that purpose you need to choose the right name of a group. You need to create group on app portal developer site and need to add that group in your both application bundle ids. after that, you will be able to use those cookies. For more information please check this thread. Cookies storage