1
我正在開發針對firefox操作系統的應用程序,並且出現報警問題。如果手機被鎖定,警報不會觸發。如果手機處於阻止狀態,則報警丟失
手機處於阻止狀態時會出現問題,因爲通知桌面不會觸發。但是,當您解鎖手機時,該APP將處於後臺,但沒有任何事情發生。
編輯
解決方案中的代碼。然後,我認爲問題消失了。
我可以利用這個功能添加報警:
// the solution for the app working right is writting this window.onload function
window.onload = function() {
function addAlarm(){
// Data alarm will be fire
var myDate = new Date();
myDate.setMinutes(myDate.getMinutes()+1);
// information for alarm
var data = {
foo: "bar"
}
var request = navigator.mozAlarms.add(myDate, "ignoreTimezone", data);
request.onsuccess = function() {
console.log("La alarma ha sido programada");
};
request.onerror = function() {
console.log("Ha ocurrido un error: " + this.error.name);
};
}
//That get the alarm event to fire the alarm and also add a desktop notification.
navigator.mozSetMessageHandler("alarm", function (mozAlarm) {
console.log('fired Alarm');
// function that add a desktop notification
notifyMe();
$('#alarmFired').append('<p>alarm fired: '+JSON.stringify(mozAlarm)+'</p>');
});
}
功能的桌面通知:
function notifyMe() {
var options = {body: "notification body", icon : 'http://www.famfamfam.com/lab/icons/mini/icons/icon_accept.gif'}
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}
// Let's check if the user is okay to get some notification
else if (Notification.permission === "granted") {
// If it's okay let's create a notification
var notification = new Notification("Hi there!", options);
}
// Otherwise, we need to ask the user for permission
// Note, Chrome does not implement the permission static property
// So we have to check for NOT 'denied' instead of 'default'
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
// Whatever the user answers, we make sure we store the information
if(!('permission' in Notification)) {
Notification.permission = permission;
}
// If the user is okay, let's create a notification
if (permission === "granted") {
var notification = new Notification("Hi there!", options);
}
});
}
notification.onclick = function(){
console.log('clicked notification');
openApp();
}
}
請使用回答發佈答案,不要在問題中編輯它。在同一頁面上:不要使用答案作爲評論,說你已經在你的問題中回答:)。聽起來令人困惑,但基本上只是將問題用於問題以及答案和答案,而且你會很好 – Nanne