- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这就是 firebase 文档描述获取 token 功能的方式:
getToken ( options ? : { serviceWorkerRegistration ?: ServiceWorkerRegistration ; vapidKey ?: string } ) : Promise < string >
Optional options: { serviceWorkerRegistration?: ServiceWorkerRegistration; vapidKey?: string }
Optional serviceWorkerRegistration?: ServiceWorkerRegistrationThe service worker registration for receiving push messaging. If the registration is not provided explicitly, you need to have a firebase-messaging-sw.js at your root location. See Retrieve the current registration token for more details.
我只是想弄清楚如何在我的代码中使用 service worker 选项。我是否像这样将文件位置放在 getToken('/file-location') 内?或者我是否导入一个注册我的自定义 Firebase 服务 worker 的函数?我可能只是愚蠢,但这些文档是准系统。
最佳答案
如果您的 (web) 服务器根目录中有 firebase-messaging-sw.js
,您只需调用 .getToken()
,您的 service worker 就会自动加载和使用。
如果您的 firebase-messaging-sw.js
位于 /my-other-folder
,那么您需要这样调用它:
const swRegistration = await navigator.serviceWorker.register('/my-other-folder/firebase-messaging-sw.js');
const token = await fcm.getToken({
serviceWorkerRegistration: swRegistration,
});
关于javascript - FCM : firebase getToken options( ServiceWorkerRegistration, vapidKey),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64126505/
这就是 firebase 文档描述获取 token 功能的方式: getToken ( options ? : { serviceWorkerRegistration ?: ServiceWorker
我是一名优秀的程序员,十分优秀!