码迷,mamicode.com
首页 > 移动开发 > 详细

ios的坑

时间:2017-01-20 07:14:39      阅读:306      评论:0      收藏:0      [点我收藏+]

标签:模式   查看   properly   测试   safari   most   mon   没有   无法   

我们的一个小应用,用localStorage做了下缓存,测试上线之后有反馈页面数据拉取不到,

最后定位到是localStorage有问题。

是Private Browsing Mode引起的。然后查看IOS的safari没有发现隐私设置什么的

后来点击右下角小框框发现有个无痕浏览的模式。MD,关闭后一切正常

复制代码
// Safari, in Private Browsing Mode, looks like it supports localStorage but all calls to setItem
// throw QuotaExceededError. We‘re going to detect this and just silently drop any calls to setItem
// to avoid the entire page breaking, without having to do a check at each usage of Storage.
if (typeof localStorage === ‘object‘) {
try {
localStorage.setItem(‘localStorage‘, 1);
localStorage.removeItem(‘localStorage‘);
} catch (e) {
Storage.prototype._setItem = Storage.prototype.setItem;
Storage.prototype.setItem = function() {};
alert(‘Your web browser does not support storing settings locally. In Safari, the most common cause of this is using "Private Browsing Mode". Some settings may not save or some features may not work properly for you.‘);
}
}
复制代码
。提示用户关闭无痕模式。

***************************************************
try {
localStorage.setItem(key, d);
} catch (e) {
alert("您处于无痕浏览,无法为您保存");
}

ios的坑

标签:模式   查看   properly   测试   safari   most   mon   没有   无法   

原文地址:http://www.cnblogs.com/crazycode2/p/6309215.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!