IOS下的safari下localStorage不起作用的问题
我们的一个小应用,使用百度地图API获取到用户的坐标之后用localStorage做了下缓存,测试上线之后有运营同学反馈页面数据拉取不到,
测试的时候没有发现问题,而且2台相同的iphone一台可以一台不行,最后定位到是localStorage有问题。
但是为啥明明版本一样的2台手机一台可以一台不行呢?
而且2台手机打印localStorage明明都是Object,奇怪了。
在度娘上没找到答案,最后到google发现有人说是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.');
}
}
可以酱紫判断。提示用户关闭无痕模式。
IOS下的safari下localStorage不起作用的问题的更多相关文章
- IOS下的safari不支持localStorage?
同事在统计日志的时候,想用localStorag去记载一些什么,但是在各大浏览器都运行的良好的基础上,唯独IOS下的safari一直静静无声,没有任何反应.打印localStorage都是Object ...
- Safari 下用 "location.href = filePath" 实现下载功能的诡异 bug
Safari 下的一些诡异 bug 我们已经领教一二,比如前文中说的 无痕浏览模式下使用 localStorage 的 API 就会报错.今天我们要讲的是利用 location.href = file ...
- 李洪强iOS经典面试题下
李洪强iOS经典面试题下 21. 下面的代码输出什么? @implementation Son : Father - (id)init { self = [super init]; if (self) ...
- iOS 点击cell下拉
iOS 点击cell下拉 代码如下: #import "ViewController.h" @interface ViewController ()<UITableView ...
- ios学习--iphone 实现下拉菜单
原文地址:ios学习--iphone 实现下拉菜单作者:sdglyuan00 #import @interface DropDown1 : UIView <</span>UITabl ...
- iOS 在 ARC 环境下 dealloc 的使用、理解误区
iOS 在 ARC 环境下 dealloc 的使用.理解误区 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致&qu ...
- iOS - UIButton设置文字标题下划线以及下划线颜色
创建button设置可以折行显示 - (void)viewDidLoad { [super viewDidLoad]; UIButton * button = [[UIButton alloc] in ...
- 【iOS】使用safari对webview进行调试
[iOS]使用safari对webview进行调试 在web开发的过程中,抓包.调试页面样式.查看请求头是很常用的技巧.其实在iOS开发中,这些技巧也能用(无论是模拟器还是真机),不过我们需要用到ma ...
- 总结下Mac环境下按照appium
第10天休息 先来总结下Mac环境下按照appium 一.相关网站 官网: http://appium.io/ 测试论坛 https://testerhome.com/wiki 二.环境准备 从官 ...
随机推荐
- 2019牛客暑期多校训练营(第五场)B.generator 1
传送门:https://ac.nowcoder.com/acm/contest/885/B 题意:给出,由公式 求出 思路:没学过矩阵快速幂.题解说是矩阵快速幂,之后就学了一遍.(可以先去学一下矩阵快 ...
- LCA 最近公共祖先 Tarjan(离线)算法的基本思路及其算法实现
首先是最近公共祖先的概念(什么是最近公共祖先?): 在一棵没有环的树上,每个节点肯定有其父亲节点和祖先节点,而最近公共祖先,就是两个节点在这棵树上深度最大的公共的祖先节点. 换句话说,就是两个点在这棵 ...
- python集合运算
用 |,& 代替 并 和交 的运算.+, -代替并和差集.
- maven坐标 加速下载
<repositories> <repository> <id>aliyun</id> <name>aliyun</name> ...
- 吴裕雄--天生自然 PYTHON3开发学习:字典
dict = {'} dict1 = { 'abc': 456 } dict2 = { 'abc': 123, 98.6: 37 } dict = {'Name': 'Runoob', 'Age': ...
- 解决 WinForm 重写 CreateParams 隐藏窗口以后的显示问题
WinForm 启动时隐藏窗体最简单有效的办法是重写 CreateParams protected override CreateParams CreateParams { get { base.Vi ...
- VirtualBox虚拟机安装
目录 安装前准备 1.开始安装,安装很简单,直接上图 2.设置全局路径,这里主要是方便以后创建虚拟机的时候不用每次都去选择存放位置,默认是存放到C盘 安装前准备 系统:Windows 10 专业版 软 ...
- [LC] 796. Rotate String
We are given two strings, A and B. A shift on A consists of taking string A and moving the leftmost ...
- P2486 [SDOI2011]染色 区间合并+树链剖分(加深对线段树的理解)
#include<bits/stdc++.h> using namespace std; ; struct node{ int l,r,cnt,lazy; node(,,,):l(l1), ...
- 系统学习Javaweb8----JavaScript4(结束)
学习内容: 1.DOM对象 1.2DOM对象--元素对象常见属性 2.JS事件 2.1JS事件--入门案例 2.2JS事件--驱动机制 2.3常见JS事件--点击事件 2.4常见JS事件--点击事件 ...