D
D
Dima Grib2021-01-07 15:28:02
HTTP Cookies
Dima Grib, 2021-01-07 15:28:02

How to update and save a Cookie value?

Please tell me how to change the value in saved cookies and overwrite them.

let data: Data? = self.defaults.object(forKey: saveCookie) as? Data
        if let cookie = data {
            let datas: NSArray? = NSKeyedUnarchiver.unarchiveObject(with: cookie) as? NSArray
            if let cookies = datas {
                print(" CookieHandler Cookie OLD - \(String(describing: cookies))")
                var test = ""
                let fileArray = cookies.value(forKey: "expiresDate")
                let resultString = String(describing: fileArray)
                test = resultString.replacingOccurrences(of: "2022-01-05 16:19:42 +0000", with: "2021-01-05 00:00:01 +0000")
                 // нужен каст обратно в NSArray. И обновить тем что получили в replacingOccurrences, старые значения в куки
                cookies.setValue(resultNSarray, forKey: "expiresDate") // Тут происходит краш, поскольку 'NSUnknownKeyException', reason: '[<NSHTTPCookie 0x282886b50> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key expiresDate
}


Cookies
(
    "<NSHTTPCookie\n\tversion:1\n\tname:token\n\tvalue:o4OzXv\n\texpiresDate:'2022-01-05 16:19:42 +0000'\n\tcreated:'2021-01-06 16:19:42 +0000'\n\tsessionOnly:FALSE\n\tdomain:.inam.com\n\tpartition:none\n\tsameSite:none\n\tpath:/\n\tisSecure:TRUE\n path:\"/\" isSecure:TRUE>",

    "<NSHTTPCookie\n\tversion:1\n\tname:did\n\tvalue:183B4\n\texpiresDate:'2023-01-06 16:19:11 +0000'\n\tcreated:'2021-01-06 16:19:11 +0000'\n\tsessionOnly:FALSE\n\tdomain:.inam.com\n\tpartition:none\n\tsameSite:none\n\tpath:/\n\tisSecure:TRUE\n\tisHTTPOnly: YES\n path:\"/\" isSecure:TRUE isHTTPOnly: YES>",

    "<NSHTTPCookie\n\tversion:1\n\tname:mid\n\tvalue:d5uB1zK5-\n\texpiresDate:'2023-01-06 16:19:11 +0000'\n\tcreated:'2021-01-06 16:19:11 +0000'\n\tsessionOnly:FALSE\n\tdomain:.inam.com\n\tpartition:none\n\tsameSite:none\n\tpath:/\n\tisSecure:TRUE\n path:\"/\" isSecure:TRUE>",

    "<NSHTTPCookie\n\tversion:1\n\tname:rcb\n\tvalue:1\n\texpiresDate:'2022-01-06 16:19:11 +0000'\n\tcreated:'2021-01-06 16:19:11 +0000'\n\tsessionOnly:FALSE\n\tdomain:.inam.com\n\tpartition:none\n\tsameSite:none\n\tpath:/\n\tisSecure:TRUE\n path:\"/\" isSecure:TRUE>",

    "<NSHTTPCookie\n\tversion:1\n\tname:uid\n\tvalue:277609\n\texpiresDate:'2021-01-28 21:33:29 +0000'\n\tcreated:'2020-12-29 21:33:29 +0000'\n\tsessionOnly:FALSE\n\tdomain:.app.com\n\tpartition:none\n\tsameSite:lax\n\tpath:/\n\tisSecure:FALSE\n\tisHTTPOnly: YES\n path:\"/\" isSecure:FALSE isHTTPOnly: YES>"
)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question