Thanks foryour answer!
I would say it’s not recommended to rely on Cookies. It is not guaranteed that iOS and Android will keep them around.
I read this multiple times but after reading a lot of forum posts/ stackoverflow etc. it looks more like an opinion, not like an actual fact. What I found is that cookies set using document.cookie and 3rd party cookies are restricted to a 7-day life-time on iOS due to Apple’s ITP https://documentation.mapp.com/1.0/en/intelligent-tracking-prevention-itp-2-1-7239974.html - that totally makes sense…
When using capacitor/http my understanding is that you get the cookies from your “own” API as first party cookies because capacitor/http proxies all the fetch/ XMLHttpRequests through native code which then also stores the cookie in the native cookie store and also uses the cookies from there for subsequent requests.
The code from capacitor/http sets the cookies to HTTPCookieStorage.
public func setCookie(_ domain: String, _ action: String) {
let url = getServerUrl(domain)!
let jar = HTTPCookieStorage.shared
let field = ["Set-Cookie": action]
let cookies = HTTPCookie.cookies(withResponseHeaderFields: field, for: url)
jar.setCookies(cookies, for: url, mainDocumentURL: nil)
syncCookiesToWebView()
}
Until now I couldn’t find anything in Apple’s docs that this cookie storage or single cookies get deleted at any time. That may be the case but other devs having problems with cookies is no real proof that it’s like that as you can do a lot of things wrong with them, leaving iOS out of the equation.
The most recent conversation about this is over here where a Capacitor team member says don’t use them for native - Cookies vs. Preferences - what is more persistent?.
The post/ the answer from the ionic team member makes absolutely no sense to me - why implement a native bridge for cookies and http when you can’t and shouldn’t use it?
Edit: He just said for storing “data” you shouldn’t use Capacitor Cookies - fine - but what about storing actual cookies? @dallas maybe you can help here?
Overall, if you search this forum for posts about cookies, there are a ton with people having problems
Right, but oftentimes it’s problems with the cookie itself where they can’t get it to work in the first place. Maybe I need to ask this at some iOS dev forum to get a link to some apple doc which states that cookies get deleted after xyz time or under which circumstances…