问题描述
当我关闭并重新打开iOS Safari(和Chrome)上的浏览器时,我的持久性cookie被删除。我在iOS 11上,但也在iOS10 / 9上进行了测试。 Cookies可以在Android和台式机上正常存在。奇怪的是,它在iOS上的Firefox上运行良好。
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 correctly on Android and desktop. And strangely, it works fine for Firefox on iOS.
我在这里缺少什么?
这是我的javascript代码设置cookie和到期日期:
Here is my javascript code the sets the cookie and expire date:
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 + ";path=/";
}
setCookie("test", "random test value", 365);
推荐答案
我刚刚遇到了Cookie被在生产服务器上进行测试时,在Android /桌面设备上保持持久,但在iOS11上不持久。解决方案似乎是在定义Cookie的域:
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在接受cookie方面似乎更受限制。我发现很多营销模糊之处在于它对于隐私保护更好,但是根据新的限制,关于如何正确实施事物(例如,永久登录/ SSO)的技术细节很少。谁能推荐任何有用的链接?
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?
这篇关于iOS Safari / Chrome中的Cookie持久性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!