Firebase Cloud Messaging无法与三星互联网一起使用。

问题描述 投票:3回答:1

我正在设置Firebase Cloud Messaging来做网络上的推送通知。到目前为止,只有Chrome(Windows和Android)和Firefox(Android)可以使用。在Samsung Internet Browser(预装在三星手机上的浏览器)上也不行,在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开始支持,设备有v9,需要注意的是,即使是在接收到的设备上,当我点击它时,也无法打开我设置的网站。fcm_options 也不遵循振动模式,但它确实会加载图标。

更新:从2020年4月起,FCM与iOS Chrome和Safari完全不兼容。

firebase firebase-cloud-messaging samsung-mobile web-push samsung-internet
1个回答
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);
});
© www.soinside.com 2019 - 2024. All rights reserved.