I'm having problems with notifications in my app.

I've seen some pages reference to the AlarmAPI in Firefox OS and how to handle notifications:

The code is basically the same in both cases and it only works when my app is open or in background. If I close my app it doesn't show notifications. I've tested the example app from the second link and it works when the app is closed.

What could the problem be and how can I fix it?

Thanks.

有帮助吗?

解决方案

you must use navigator.mozSetMessageHandler() https://developer.mozilla.org/en-US/docs/Web/API/Navigator.mozSetMessageHandler

 if(navigator.mozSetMessageHandler) {
   navigator.mozSetMessageHandler("alarm", function (alarm) {
   // only launch a notification if the Alarm is of the right type for this app
   if(alarm.data.task) {
    // Create a notification when the alarm is due
    new Notification("Your task " + alarm.data.task + " is now due!");
    updateNotified(alarm.data.task);
  }
  });
  }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top