Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在推送通知时访问本地存储_Javascript_Android_Angularjs_Push Notification_Ionic - Fatal编程技术网

Javascript 在推送通知时访问本地存储

Javascript 在推送通知时访问本地存储,javascript,android,angularjs,push-notification,ionic,Javascript,Android,Angularjs,Push Notification,Ionic,在ionic应用程序中,我试图在推送通知到达时将一些数据保存到本地存储,但在推送通知到达时保存到本地存储的数据似乎总是空的。ionic push的onNotification事件处理程序中是否没有对window.localStorage的访问权限 这是我的密码: $ionicPush.register({ canShowAlert: true, //Can pushes show an alert on your screen? canSetBadge: true, //Can

在ionic应用程序中,我试图在推送通知到达时将一些数据保存到本地存储,但在推送通知到达时保存到本地存储的数据似乎总是空的。ionic push的onNotification事件处理程序中是否没有对window.localStorage的访问权限

这是我的密码:

$ionicPush.register({
    canShowAlert: true, //Can pushes show an alert on your screen?
    canSetBadge: true, //Can pushes update app icon badges?
    canPlaySound: true, //Can notifications play a sound?
    canRunActionsOnWake: true, //Can run actions outside the app,
    onNotification: function(notification) {
    window.localStorage.setItem('someData', notification.payload.somedata);
   }
})
稍后在应用程序中,当我尝试
window.localStorage.getItem('someData')
时,它总是空的。

您好,我正在使用插件,只是存储在localStorage中

$cordovaPush.register(androidConfig).then(function(result) {
console.log(result);
try {
    window.localStorage.setItem("pushID",result);
    } catch (e) {
    console.log(e);
    }
   }, function(err) {
    console.log(err);
  })
如果要从localstorage获取pushID====

 var pushId = window.localStorage['pushID'] || false;

它的返回值或false[如果不存在pushID]。

您是否验证了
通知.payload.somedata
在回调中不为
null
?是的,我已经验证了即使我使用window.localStorage.setItem('somedata',20),它仍然为null。这正是我正在做的,但我想知道为什么它在我的情况下不起作用。是否有任何原因使其无法在onRegister事件处理程序中访问?