Firebase Cloud Messaging无法与Samsung Internet一起使用 [英] Firebase Cloud Messaging not working with Samsung Internet

查看:131
本文介绍了Firebase Cloud Messaging无法与Samsung Internet一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置Firebase Cloud Messaging,以在网络上进行推送通知.到目前为止,它仅适用于Chrome(Windows和Android)和Firefox(Android).它无法在Samsung Internet Browser(Samsung手机上预装的浏览器)上运行,到目前为止,我还没有机会在iOS上进行测试.

I'm setting up Firebase Cloud Messaging to do push notifications on the web. It works but only with Chrome (Windows and Android) and Firefox(Android) so far. It's not working on Samsung Internet Browser (the browser that comes pre-installed on Samsung's phones) and I haven't gotten a chance to test on iOS so far.

我尝试将发件人ID作为gcm_sender_id添加到我正在使用的Cloud Function以及manifest.json文件中,但无济于事.下面是通知主体的设置方式.

I've tried adding the sender id as gcm_sender_id to the Cloud Function I'm using as well as to the manifest.json file to no avail. Below is how the notification body is set up.

// Create notification content
const notification = admin.messaging().Notification = {
    title : 'My test Title',
    body : `Lorem Ipsum Dolor`,

};

const payload = admin.messaging().Message = {
    notification,
    webpush:{
        notification : {
            vibrate: [200, 100, 200],
            icon: 'https://www.goodhousekeeping.com/life/pets/g4531/cutest-dog-breeds/', //A random dog photo
            fcm_options: {
                link: 'https://www.youtube.com',
                gcm_sender_id : '<SENDER_ID>',
            },
        },
    },
    topic: '<TOPIC>'
};
   //Send notification
   return admin.messaging().send(payload);

我可以做些什么使它在Samsung Internet上运行吗?从v4开始支持服务工作者,并且该设备具有v9.应该注意的是,即使在接收它的设备上,当我单击它时,它也不会打开我在fcm_options中设置的网站,也不会遵循振动模式,但是会加载图标.

Is there anything I can do to get this to work on Samsung Internet? Service Workers have been supported since v4 and the device has v9. It should be noted that even on the devices that receive it, when I click on it, it doesn't open up the website I set in fcm_options nor does it follow the vibrate pattern but it does load the icon.

更新:截至2020年4月,FCM与iOS Chrome和Safari完全不兼容

UPDATE: As of April 2020 FCM is completely incompatible with iOS Chrome and Safari

推荐答案

所以我知道这可能没有帮助,但它神奇地"从今天开始工作.浏览器版本为Samsung Internet v10.

So I know this probably isn't helpful but it 'magically' started working today. The browser version is Samsung Internet v10.

firebase-messaging-sw.js

firebase-messaging-sw.js

// Give the service worker access to Firebase Messaging.
// Note that you can only use Firebase Messaging here, other Firebase libraries
// are not available in the service worker.
importScripts('https://www.gstatic.com/firebasejs/7.13.2/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/7.13.2/firebase-messaging.js');


// Initialize the Firebase app in the service worker by passing in
// your app's Firebase config object.
// https://firebase.google.com/docs/web/setup#config-object
firebase.initializeApp({
    apiKey: '',
    authDomain: '',
    databaseURL: '',
    projectId: '',
    storageBucket: '',
    messagingSenderId: '',
    appId: '',
    measurementId: ''
});

// Retrieve an instance of Firebase Messaging so that it can handle background
// messages.
const messaging = firebase.messaging();

messaging.setBackgroundMessageHandler(payload => {
  console.log('[firebase-messaging-sw.js] Received background message ', payload);
  // Customize notification
  const notificationTitle = payload.data.title;
  const notificationOptions = {
    body: payload.data.body,
    priority: payload.data.priority,
    vibrate: payload.data.vibrate,
    icon: payload.data.icon,
    click_action: payload.data.link,
    link: payload.data.link
  };


  return self.registration.showNotification(notificationTitle,
    notificationOptions);
});

//Open browser window or focus it if it is open on notification click
self.addEventListener('notificationclick', function(event) {
  event.notification.close();
  event.waitUntil(self.clients.openWindow('www.yourwebsitehere.com'));
});

云功能发送通知

//Sends notifications to users when the statistics document is updated
exports.sendNotifications = functions.firestore.document('restaurant/statistics').onUpdate(async (snapshot,context) =>{
    //Get updated document data
    const updatedData = snapshot.after.data();

    const payload = admin.messaging().Message = {
        data: {
            title: updatedData.title,
            body : updatedData.body,
            icon: updatedData.icon,
            link: updatedData.link,
            vibrate: "[300, 200, 300]",
            priority: "high"
         },
        topic: 'statistics'
    }

    return admin.messaging().send(payload);
});

这篇关于Firebase Cloud Messaging无法与Samsung Internet一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆