0

我有一个使用 Phonegap 和 Backbone 的 iOS 应用程序,并且在通过 xCode 或 Testflight 全新安装应用程序时,本地存储不会保留发送给它的任何值。在每个屏幕上,本地存储值都为空。但是,如果应用程序退出然后重新启动,本地存储似乎工作正常。即使我从 xCode 再次安装该应用程序也很好,它仅在删除应用程序和全新安装时不起作用。有任何想法吗?这是我的本地存储线:

window.localStorage.setItem("user_name", "emailaddress");

更新 1:这个问题实际上似乎与骨干有关。在我的主要 home_view.js 声明中,我调用:

var View = require('./view');
var template = require('./templates/home'); 
var Posts = require('../models/posts');
var user_name = window.localStorage.getItem("user_name");

然后在渲染函数中 user_name 为 null 但这似乎解决了这个问题:

    if (user_name == null) {
        location.reload();
    }

如果我设置:

    var user_name = window.localStorage.getItem("user_name");

在渲染函数中,user_name 是为 homeview.js 定义的,但不在任何其他 js 文件中。

4

0 回答 0