admin管理员组文章数量:1312967
So this is how the firebase docs describe the get token function:
getToken ( options ? : { serviceWorkerRegistration ?: ServiceWorkerRegistration ; vapidKey ?: string } ) : Promise < string >
Optional options: { serviceWorkerRegistration?: ServiceWorkerRegistration; vapidKey?: string }
Optional serviceWorkerRegistration?: ServiceWorkerRegistration The 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.
I'm just trying to figure out how to use the service worker option in my code. Do I just put the file location inside of the getToken('/file-location') like this? Or do I import a function that registers my custom firebase service worker? I might just be stupid but these docs are barebones.
So this is how the firebase docs describe the get token function:
getToken ( options ? : { serviceWorkerRegistration ?: ServiceWorkerRegistration ; vapidKey ?: string } ) : Promise < string >
Optional options: { serviceWorkerRegistration?: ServiceWorkerRegistration; vapidKey?: string }
Optional serviceWorkerRegistration?: ServiceWorkerRegistration The 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.
I'm just trying to figure out how to use the service worker option in my code. Do I just put the file location inside of the getToken('/file-location') like this? Or do I import a function that registers my custom firebase service worker? I might just be stupid but these docs are barebones.
Share Improve this question edited Sep 29, 2020 at 19:39 Doug Stevenson 318k36 gold badges454 silver badges472 bronze badges asked Sep 29, 2020 at 19:38 Officer_NarcOfficer_Narc 3041 gold badge4 silver badges16 bronze badges1 Answer
Reset to default 10If you have your firebase-messaging-sw.js
in your (web)server root, you can just call .getToken()
, and your service worker will be automatically loaded and used.
If you have your firebase-messaging-sw.js
at /my-other-folder
, then you will need to call it this way:
const swRegistration = await navigator.serviceWorker.register('/my-other-folder/firebase-messaging-sw.js');
const token = await fcm.getToken({
serviceWorkerRegistration: swRegistration,
});
本文标签: javascriptFCM firebase getToken options( ServiceWorkerRegistrationvapidKey)Stack Overflow
版权声明:本文标题:javascript - FCM: firebase getToken options( ServiceWorkerRegistration, vapidKey) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741890921a2403296.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论