我 文件出现问题。我已经通过以下代码解决了这个问题。
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 = { apiKey: "AIzaSyDtg4aQMQW67Jla1nUzrTTSEhVqpUeqKXI", authDomain: "payxxxxxxx.firebaseapp.com", databaseURL: "https://pxyxxxxx.firebaseio.com", projectId: "pxxoll-pxxxs-fxxx", storageBucket: "pxxx-pxxx-fxxxx1.apxxxot.com", messagingSenderId: "2xxxx5xxx" }; firebase.initializeApp(config); const messaging = firebase.messaging ;解决方法
我正在尝试使用云功能将FCM发送到我的React应用程序。云功能正在执行,但客户端未收到通知。
这里是云功能代码。
exports.sendPush = functions.database.ref('/settings2').onWrite(event => { let projectStateChanged = false; let projectCreated = false; let projectData = event.data.val ; if (!event.data.previous.exists ) { projectCreated = true; } if (!projectCreated && event.data.changed ) { projectStateChanged = true; } let msg = 'A project state was changed'; if (projectCreated) { msg = `The following new project was added to the project: ${projectData.title}`; } tokens.push("fIGxxxxGtDGxxxx DEVICE Token"); let payload = { notification: { title: 'Firebase Notification',body: 'This Is Message',sound: 'default',badge: '1' } }; return admin.messaging .sendToDevice(tokens,payload); });
这是Cloud功能的日志
这是我客户端上的代码:
messaging.onMessage(function(payload) { console.log("Message received. ",payload); // ... });
没有任何错误,但控制台中没有任何内容。我是否需要对服务工作者文件进行某些处理?
任何帮助,将不胜感激。
评论列表