【发布时间】:2016-01-10 19:30:50
【问题描述】:
在 ionic 应用程序中,我试图在推送通知到达时将一些数据保存到本地存储,但似乎我在推送通知到达时保存到本地存储的数据始终为空。离子推送的 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') 时,它始终为空。
【问题讨论】:
-
您是否确认
notification.payload.somedata在您的回调中不是null? -
是的,我已经验证它不为空
-
即使我做了window.localStorage.setItem('someData', 20),它仍然是null
标签: javascript android angularjs push-notification ionic