【发布时间】:2018-03-28 21:12:37
【问题描述】:
这是我的代码:
firebase.initializeApp(config);
if(!window.Notification){
alert('Not supported');
}else{
Notification.requestPermission().then(function(p){
if(p=='denied'){
alert('You denied to show notification');
}else if(p=='granted'){
alert('You allowed to show notification');
}
});
}
var database = firebase.database().ref("sensor/Motion");
database.on('child_added', function() {
$("#Mt").val("Motion detected");
$("#dateM").val( moment().format('LLL') );
if(Notification.permission!=='default'){
var notification = new Notification('Alert', {
icon: 'alert-icon-red.png',
body: "Motion detected!",
});
}else{
alert('Please allow the notification first');
}
在我的桌面浏览器中一切正常,但在我的 Android 设备上,当屏幕锁定时,它可以工作几分钟,然后就无法工作。我没有收到任何通知。
【问题讨论】:
标签: javascript jquery firebase firebase-realtime-database