javascript - Web Push Notification FCM on Mobile -
i'm trying send push notification users in web app not working on mobile.
i'm using vuejs + firebase, use cloud function send notification , in service worker, receive , handle show user.
it works in browser on pc, don't work in mobile 'android', here code:
cloud function:
}).then(function (atokens) { const payload = { data: { title: 'test-title', body: 'test-body' } } // send notifications tokens. return admin.messaging().sendtodevice(atokens, payload).then(res => { res.results.foreach((result, index) => { const error = result.error if (error) { console.error('failure sending notification to', tokens[index], error) } }) response.send('ok') }) })
service-worker function:
importscripts('https://www.gstatic.com/firebasejs/3.9.0/firebase-app.js'); importscripts('https://www.gstatic.com/firebasejs/3.9.0/firebase- messaging.js'); var config = { messagingsenderid: "1033425324523" } firebase.initializeapp(config); var messaging = firebase.messaging(); messaging.setbackgroundmessagehandler(function (payload) { var title = payload.data.title; var options = { body: payload.data.body }; return self.registration.shownotification(title, options); });
in browser notification work see image:
but in android doesn't work, have last version or chrome , firefox , tested in both, put web app in home screen , allowed send notification too. notifications never show there.
what need include see push notifications on mobile too?
Comments
Post a Comment