admin管理员组文章数量:1295912
I'm using flutter web with firebase_messaging
I tried to follow the documentation's steps:
I created a VAPID:
I'm getting the token with
await FirebaseMessaging.instance.requestPermission(provisional: true);
final fmcToken = await FirebaseMessaging.instance.getToken(
vapidKey: kIsWeb
? 'xxx'
: null,
);
print('token: $fmcToken');
:
which gives me a token:
Launching lib/main.dart on Chrome in debug mode...
This app is linked to the debug service: ws://127.0.0.1:63406/1xasoU1wJzY=/ws
Debug service listening on ws://127.0.0.1:63406/1xasoU1wJzY=/ws
Connecting to VM Service at ws://127.0.0.1:63406/1xasoU1wJzY=/ws
token: xxx
I'm then using it to send a test notification:
But I'm not receiving any notification.
I did allowed the notifications:
I also included the web/firebase-messaging-sw.js
:
importScripts(".11.1/firebase-app-compat.js");
importScripts(".11.1/firebase-messaging-compat.js");
firebase.initializeApp({
apiKey: 'xxx',
appId: 'xxx',
messagingSenderId: 'xxx',
projectId: 'xxx',
authDomain: 'xxx',
storageBucket: 'xxx',
measurementId: 'xxx',
});
// Necessary to receive background messages:
const messaging = firebase.messaging();
// Optional:
messaging.onBackgroundMessage((m) => {
console.log("onBackgroundMessage", m);
});
and here is my web/index.html
:
<body>
<script>
window.addEventListener("load", function (ev) {
// Download main.dart.js
_flutter.loader.loadEntrypoint({
serviceWorker: {
serviceWorkerVersion: serviceWorkerVersion,
},
onEntrypointLoaded: function (engineInitializer) {
engineInitializer.initializeEngine().then(function (appRunner) {
appRunner.runApp();
});
},
});
});
</script>
<script>
if ("serviceWorker" in navigator) {
window.addEventListener("load", function () {
navigator.serviceWorker.register("firebase-messaging-sw.js", {
scope: "/firebase-cloud-messaging-push-scope",
});
});
}
</script>
What am I missing?
I'm using flutter web with firebase_messaging
I tried to follow the documentation's steps:
I created a VAPID:
I'm getting the token with
await FirebaseMessaging.instance.requestPermission(provisional: true);
final fmcToken = await FirebaseMessaging.instance.getToken(
vapidKey: kIsWeb
? 'xxx'
: null,
);
print('token: $fmcToken');
:
which gives me a token:
Launching lib/main.dart on Chrome in debug mode...
This app is linked to the debug service: ws://127.0.0.1:63406/1xasoU1wJzY=/ws
Debug service listening on ws://127.0.0.1:63406/1xasoU1wJzY=/ws
Connecting to VM Service at ws://127.0.0.1:63406/1xasoU1wJzY=/ws
token: xxx
I'm then using it to send a test notification:
But I'm not receiving any notification.
I did allowed the notifications:
I also included the web/firebase-messaging-sw.js
:
importScripts("https://www.gstatic/firebasejs/10.11.1/firebase-app-compat.js");
importScripts("https://www.gstatic/firebasejs/10.11.1/firebase-messaging-compat.js");
firebase.initializeApp({
apiKey: 'xxx',
appId: 'xxx',
messagingSenderId: 'xxx',
projectId: 'xxx',
authDomain: 'xxx',
storageBucket: 'xxx',
measurementId: 'xxx',
});
// Necessary to receive background messages:
const messaging = firebase.messaging();
// Optional:
messaging.onBackgroundMessage((m) => {
console.log("onBackgroundMessage", m);
});
and here is my web/index.html
:
<body>
<script>
window.addEventListener("load", function (ev) {
// Download main.dart.js
_flutter.loader.loadEntrypoint({
serviceWorker: {
serviceWorkerVersion: serviceWorkerVersion,
},
onEntrypointLoaded: function (engineInitializer) {
engineInitializer.initializeEngine().then(function (appRunner) {
appRunner.runApp();
});
},
});
});
</script>
<script>
if ("serviceWorker" in navigator) {
window.addEventListener("load", function () {
navigator.serviceWorker.register("firebase-messaging-sw.js", {
scope: "/firebase-cloud-messaging-push-scope",
});
});
}
</script>
What am I missing?
Share Improve this question edited Feb 12 at 15:55 Frank van Puffelen 600k85 gold badges889 silver badges859 bronze badges Recognized by Google Cloud Collective asked Feb 12 at 2:56 Valentin VignalValentin Vignal 8,2784 gold badges40 silver badges95 bronze badges 2- Please do not upload images of code/data/errors. - Please edit and provide the code/data/errors as text. - Furthermore this looks like an SSL issue on your localhost – DarkBee Commented Feb 12 at 8:30
- I edited the post to include more information and add the code/logs that was in the screenshots. Can you elaborate a bit on "this looks like an SSL issue on your localhost"? What does that mean and how can I troubleshoot/fix it ? – Valentin Vignal Commented Feb 12 at 15:03
1 Answer
Reset to default 0Do you have the firebase-messaging-sw.js file under your web directory? To receive push notifications, you need to set up a Service Worker at first.
Link
本文标签: Flutter webno firebase messaging notifications on macosStack Overflow
版权声明:本文标题:Flutter web - no firebase messaging notifications on macos - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741623619a2388956.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论