【问题标题】:Firebase Cloud Messaging not working with Samsung InternetFirebase Cloud Messaging 不适用于三星互联网
【发布时间】:2020-03-30 08:10:54
【问题描述】:

我正在设置 Firebase Cloud Messaging 以在网络上推送通知。到目前为止,它仅适用于 Chrome(Windows 和 Android)和 Firefox(Android)。它不适用于三星互联网浏览器(三星手机上预装的浏览器),到目前为止我还没有机会在 iOS 上进行测试。

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

// 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);

我可以做些什么来让它在三星互联网上运行?从 v4 开始支持 Service Worker,并且该设备具有 v9。需要注意的是,即使在接收它的设备上,当我点击它时,它并没有打开我在fcm_options 设置的网站,也没有遵循振动模式,但它确实加载了图标。

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

【问题讨论】:

    标签: firebase firebase-cloud-messaging samsung-mobile web-push samsung-internet


    【解决方案1】:

    所以我知道这可能没有帮助,但它“神奇地”从今天开始起作用。浏览器版本为三星互联网v10。

    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);
    });
    

    【讨论】:

    • 这个三星浏览器甚至没有提供禁用推送通知以重置注册令牌的方法,关于如何处理这个问题的任何想法?
    • @andreszs 尝试清除缓存并删除站点数据?
    • 谢谢,但应该有另一种方法.. 所有三星手机都附带此浏览器?我们注定要失败
    • 它没有在我的应用程序中生成令牌,chrome 正在生成。我该怎么做才能解决这个问题?
    • @user2828442 您应该提出一个单独的问题并将其链接到此处。那我很乐意看看
    猜你喜欢
    • 1970-01-01
    • 2022-01-09
    • 2021-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-31
    • 2023-03-21
    • 1970-01-01
    相关资源
    最近更新 更多