相关疑难解决方法(0)

PWA 可以在关闭时安排通知吗?

我正在开发一个 TODO 列表 PWA,即使应用程序关闭,它也应该在每天上午 8:00 显示当天的任务(类似于闹钟)。

有没有办法通过 PWA 来实现这一目标?(主要针对Chrome/Android)

到目前为止,在我的服务人员中我已经(简化)


self.addEventListener("message", (event) => {
    // Workflow: The app sends a message that the timer should be set.
    const prom = new Promise((resolveIt) =>
      self.setTimeout(() => showAlarmAndResolve(resolveIt, event.data), '<timeout_in_ms>')
    );
    // tell the service worker to remain alive until promise is resolved
    event.waitUntil(prom); 
  }
});

async function showAlarmAndResolve(resolveIt, text) {
  const options = {
    body: text,
    tag: "todo-alert",
  };
  await self.registration.showNotification(
    "Your tasks for today",
    options
  );
  resolveIt();   // allow the …
Run Code Online (Sandbox Code Playgroud)

service-worker progressive-web-apps

6
推荐指数
1
解决办法
2000
查看次数

渐进式Web应用程序中的后台事件?(构建闹钟应用)

我在玩渐进式Web应用程序,而我想尝试构建的一种情况是闹钟应用程序。

我认为要使此应用正常运行,必须在内部条件(当前时间===警报时间)得到满足后,才能在后台运行并激活。

这可能吗?或者,渐进式Web应用程序尚未具有通过API在后台/访问电话功能中进行操作的自由。

谢谢!

progressive-web-apps

5
推荐指数
1
解决办法
1343
查看次数