我们的一个小应用,使用百度地图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不起作用的问题的更多相关文章

  1. IOS下的safari不支持localStorage?

    同事在统计日志的时候,想用localStorag去记载一些什么,但是在各大浏览器都运行的良好的基础上,唯独IOS下的safari一直静静无声,没有任何反应.打印localStorage都是Object ...

  2. Safari 下用 "location.href = filePath" 实现下载功能的诡异 bug

    Safari 下的一些诡异 bug 我们已经领教一二,比如前文中说的 无痕浏览模式下使用 localStorage 的 API 就会报错.今天我们要讲的是利用 location.href = file ...

  3. 李洪强iOS经典面试题下

    李洪强iOS经典面试题下 21. 下面的代码输出什么? @implementation Son : Father - (id)init { self = [super init]; if (self) ...

  4. iOS 点击cell下拉

    iOS  点击cell下拉 代码如下: #import "ViewController.h" @interface ViewController ()<UITableView ...

  5. ios学习--iphone 实现下拉菜单

    原文地址:ios学习--iphone 实现下拉菜单作者:sdglyuan00 #import @interface DropDown1 : UIView <</span>UITabl ...

  6. iOS 在 ARC 环境下 dealloc 的使用、理解误区

    iOS 在 ARC 环境下 dealloc 的使用.理解误区 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致&qu ...

  7. iOS - UIButton设置文字标题下划线以及下划线颜色

    创建button设置可以折行显示 - (void)viewDidLoad { [super viewDidLoad]; UIButton * button = [[UIButton alloc] in ...

  8. 【iOS】使用safari对webview进行调试

    [iOS]使用safari对webview进行调试 在web开发的过程中,抓包.调试页面样式.查看请求头是很常用的技巧.其实在iOS开发中,这些技巧也能用(无论是模拟器还是真机),不过我们需要用到ma ...

  9. 总结下Mac环境下按照appium

    第10天休息 先来总结下Mac环境下按照appium 一.相关网站 官网: http://appium.io/ 测试论坛 https://testerhome.com/wiki 二.环境准备   从官 ...

随机推荐

  1. Android Studio 停靠模式(Docked Mode)

    如果之前选了任务一种模式,先全都取消了 然后点击Window -->Active Tool Window-->这个时候就可以选择Docked Mode了

  2. 实例说明 PeekMessage与GetMessage的区别

    PeekMessage与GetMessage的对比相同点:PeekMessage函数与GetMessage函数都用于查看应用程序消息队列,有消息时将队列中 的消息派发出去. 不同点:无论应用程序消息队 ...

  3. Java搭建WebSocket的两种方式

    下面分别介绍搭建方法:一.直接使用Java EE的api进行搭建.一共3个步骤:1.添加依赖<dependency>    <groupId>javax</groupId ...

  4. 蓝桥杯2015-省赛-C/C++-A组2题 星系炸弹

    在X星系的广袤空间中漂浮着许多X星人造“炸弹”,用来作为宇宙中的路标.每个炸弹都可以设定多少天之后爆炸.比如:阿尔法炸弹2015年1月1日放置,定时为15天,则它在2015年1月16日爆炸.有一个贝塔 ...

  5. 关于JavaWeb中Servlet的总结

    Servlet知识结构图 Servlet是JavaWeb服务器端的程序,一般一个Servlet处理一种特定的请求.Servlet编写好后,需要指定其所处理的请求的请求路径,也可以认为Servlet是一 ...

  6. XSL使用写法与效果

    data.xml <?xml-stylesheet type="text/xsl" href="getdata.xsl"?> <ROOT> ...

  7. bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

    ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL ...

  8. D. Coloring Edges

    You are given a directed graph with 

  9. Java中Arrays详解

    一.Arrays类的定义 Arrays类位于 java.util 包中,主要包含了操纵数组的各种方法 使用时导包:import java.util.Arrays 二.Arrays常用函数(都是静态的) ...

  10. 用bosybox制作文件系统

    在orangepi_sdk/source/busybox-1.25.0目录里有源码. ). 先清除编译出来的文件及配置文件 make distclean ). 配置busybox make menuc ...