Я разрабатываю приложение для ОС firefox, и у меня есть проблема с сигналами тревоги. Аварийные сигналы не срабатывают, если телефон заблокирован.Тревоги потеряны, если телефон заблокирован.
Проблема возникает, когда телефон находится в состоянии блокировки, поскольку рабочий стол уведомлений не срабатывает. Но APP находится на фоне, когда вы разблокируете телефон, но ничего не происходит.
EDIT
Решение в коде. Тогда, я думаю, проблема исчезла.
Я могу добавить сигналы с помощью этой функции:
// 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