Cookie persistence in iOS Safari/Chrome

后端 未结 1 914
没有蜡笔的小新
没有蜡笔的小新 2021-01-12 21:03

My persistent cookies are being deleted when I close and reopen the browser on iOS Safari (and Chrome). I\'m on iOS 11, but have tested on iOS10/9 also. The cookies persist

1条回答
  •  -上瘾入骨i
    2021-01-12 21:31

    I've just come across this problem with cookies being persistent on Android / Desktop devices but not on iOS11 when tested on a production server. The solution seemed to be defining the domain of the cookie:

      setCookie = function(cname, cvalue, exdays) {
         var d = new Date();
         d.setTime(d.getTime() + (exdays*24*60*60*1000));
         var expires = "expires="+ d.toUTCString();
         document.cookie = cname + "=" + cvalue + ";" + expires + ";domain=" + window.location.hostname + ";path=/";
      }
    
      setCookie("test", "random test value", 365);
    

    iOS11 seems to be much more locked down in terms of what cookies it accepts. I can find lots of marketing blurb about it being better for privacy but very little technical detail about how to implement things (e.g. persistent login / SSO) properly in light of the new restrictions. Can anyone recommend any useful links?

    0 讨论(0)
提交回复
热议问题