我正在开发一个 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) 我在玩渐进式Web应用程序,而我想尝试构建的一种情况是闹钟应用程序。
我认为要使此应用正常运行,必须在内部条件(当前时间===警报时间)得到满足后,才能在后台运行并激活。
这可能吗?或者,渐进式Web应用程序尚未具有通过API在后台/访问电话功能中进行操作的自由。
谢谢!