- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
问题
正如标题所说,我目前遇到一个问题,即 NSHTTPCookieStorage
在手机重启后至少解锁一次之前在后台初始化时丢失我们应用程序的 cookie。
一旦 cookie 丢失,它们将无法以任何方式恢复,迫使用户重新登录以检索一组新的 cookie 并恢复 session 。
如果应用事件是在用户解锁她/他的手机后首次注册的,那么一切都会正常进行。
上下文:
我们使用 NSURLRequest
和 NSURLSession
时也发生了这个问题使用 ASIHTTP 和 AFNetworking 自动处理 cookie,所以我们得出的结论是它影响了整个 NSHTTPCookieStorage
类。
我们的应用程序具有 SLC(重大位置变化监控),因此它
在后台自动触发。
重现步骤
等到 SLC,或者你选择的背景行为是触发并完成 CALL B。
提示:您可以禁用和启用飞行模式以在设备上强制触发 SLC。
问题:如果在此期间触发了重大的位置更改,应用程序将永远丢失所有 cookie,没有任何机会以任何方式恢复它们。
任何帮助或想法将不胜感激。
最佳答案
似乎 iOS 有 this same issue但 cookie 存储在 NSHTTPCookieStorage 上。
我已经创建了一个雷达,所以可以随意添加更多,这样这个问题就会在队列中被推高一点。雷达编号为16237165。
与此同时,您可以执行以下解决方法:
手动处理 cookie(也就是不自动依赖 iOS管理 cookie 并将它们存储在 NSHTTPCookieStorage
中类(class))。但是不要使用NSUSerDefaults
因为它有同样的问题。
在手机至少解锁一次之前阻止所有网络事件。这是我们选择的选项,我们执行了以下操作:
NSFileProtectionCompleteUntilFirstUserAuthentication
权限在磁盘中创建一个文件。这是一个代码示例:
static BOOL phoneIsUnlocked = NO;
//If this var is true, then avoid re checking if file has permissions (Cause if it was granted permissions once, it will have access now)
if(phoneIsUnlocked) return phoneIsUnlocked;
//If phone has never been unlocked, prevent all networking stuff just to make sure cookies are not lost due to an ios7 bug.
//Creates a file with NSFileProtectionCompleteUntilFirstUserAuthentication permissions. If the app is able to read it, it means the phone was unlocked at least once after a reboot.
//Get the file path
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *fileName = [documentsDirectory stringByAppendingPathComponent:@"a.secure"];
//create file if it doesn't exist
if(![[NSFileManager defaultManager] fileExistsAtPath:fileName])
[[NSFileManager defaultManager] createFileAtPath:fileName
contents:[@"secure" dataUsingEncoding:NSUTF8StringEncoding]
attributes:[NSDictionary dictionaryWithObject:NSFileProtectionCompleteUntilFirstUserAuthentication
forKey:NSFileProtectionKey]];
NSFileHandle *file = [NSFileHandle fileHandleForReadingAtPath:fileName];
phoneIsUnlocked = file != nil; //If file is not nil, the phone has been unlocked
[file closeFile];
关于ios - NSHTTPCookieStorage 丢失 cookie,如果应用程序在重启后手机至少解锁一次之前启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22646726/
在我的主要组件中,我有: mounted() { window.$cookie.set('cookie_name', userName, expiringTime); }, 这会产生以下错误:
我正在学习 cookie,并且我想知道在编写依赖 cookie 来存储状态的 Web 应用程序时浏览器的支持情况。 对于每个域/网站,可以向浏览器发送多少个 Cookie,大小是多少? 如果发送并存储
我已经为我的站点设置了一个 cdn,并将其用于 css、js 和图像。 网站只提供那些文件 我的问题是 firefox 中的页面速度插件对于我的图片请求,我看到了一个 cookie Cookie fc
在阅读了 Internet 上的文档和帖子后,我仍然无法解决 jMeter 中的 Cookie Manager 问题。 我在响应头中得到了 sid ID,但它没有存储在我的 cookie 管理器中。
我正在 Node.JS 中处理一些类似浏览器的 cookie 处理,想知道从 NodeJS and HTTP Client - Are cookies supported? 开始对这段代码进行扩展到什
我正在此堆栈上构建自托管 Web 服务器:欧文南希网络 API 2 我正在使用 Katana 的 Microsoft.Owin.Security.Cookies 进行类似表单的身份验证。我得到了 Se
我有一个从另一个网站加载资源的网站。我已经能够确定: 第三方网站在用户的浏览器上放置 cookie。 如果我在浏览器设置中禁用第三方 cookie,第三方网站将无法再在浏览器上放置 cookie。 该
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 9年前关闭。 Improve this q
我正在使用 python mechanize 制作登录脚本。我已经读到 Mechanize 的 Browser() 对象将自动处理 cookie 以供进一步请求。 我怎样才能使这个 cookie 持久
我正在尝试在 www.example.com 和 admin.other.example.com 之间共享 cookie 我已经能够使其与 other.example.com 一起使用,但是无法访问子
我设置了一个域为 .example.com 的 cookie .它适用于我网站上的每个一级子域,应该如此。 但是,它不适用于 n 级子域,即 sub.subdomain.example.com和 to
我想让用户尽可能长时间地登录。 我应该使用什么? 普通 cookies 持久性 cookie 快闪 cookies ip地址 session 或这些的某种组合? 最佳答案 我认为 Flash cook
如果给定的 Web 服务器只能读取其域内设置的 cookie,那么 Internet 广告商如何从其网络外的网站跟踪用户的 Web 流量? 是否存在某种“supercookie”全局广告系统,允许广告
我知道一个 cookie 可以容纳多少数据是有限制的,但是我们可以设置多少个 cookie 有限制吗? 最佳答案 来自 http://www.ietf.org/rfc/rfc2109.txt Prac
如果我拒绝创建 cookie,则在我的浏览器中创建名称为 __utma、__utmb 等的 cookie。我认为这个 cookie 是用于谷歌分析的。任何人都知道谷歌如何创建这个 cookie,即使浏
我有一个生产环境和一个登台环境。我想知道我是否可以在环境之间沙箱 cookie。我的设置看起来像 生产 domain.com - 前端 SPA api.domain.com - 后端节点 分期 sta
我想知道浏览器(即 Firefox )和网站的交互。 当我将用户名和密码提交到登录表单时,会发生什么? 我认为该网站向我发送了一些 cookie,并通过检查这些 cookie 来授权我。 cookie
我在两个不同的域中有两个网络应用程序 WebApp1 和 WebApp2。 我在 HttpResponse 的 WebApp1 中设置 cookie。 如何从 WebApp2 中的 HttpReque
我正在使用Dartium“Version 34.0.1847.0 aura(264987)”,并从Dart创建一个websocket。但是,如果不是httpOnly,我的安全 session cook
我从 Headfirst Javascript 书中获取了用于 cookie 的代码。但由于某种原因,它不适用于我的浏览器。我主要使用chrome和ff,并且我在chrome中启用了本地cookie。
我是一名优秀的程序员,十分优秀!