关闭应用时显示通知

时间:2014-01-31 17:37:38

标签: firefox notifications alarm firefox-os

我的应用中的通知存在问题。

我已经看到一些页面引用了Firefox OS中的AlarmAPI以及如何处理通知:

两种情况下的代码基本相同,只有在我的应用程序处于打开状态或后台时才有效。如果我关闭我的应用程序,它不会显示通知。我已经从第二个链接测试了示例应用程序,它在应用程序关闭时有效。

问题是什么?我该如何解决?

感谢。

1 个答案:

答案 0 :(得分:0)

你必须使用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);
  }
  });
  }
相关问题