Tag: firebase cloud messaging

通知不会出现在应用程序的背景状态和死亡状态

我试图在上传post时将通知推送给应用的最终用户。 它在应用程序处于前景时工作正常,但当应用程序在后台或被杀害时不显示。 有什么办法来显示应用程序被杀害或在后台运行的通知。 这里是我使用的node.js代码 const functions = require('firebase-functions'); let admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); exports.sendPush = functions.database.ref('/promos').onWrite(event => { var topic = "deals_notification"; let projectStateChanged = false; let projectCreated = false; let projectData = event.data.val(); if (((event.data.numChildren())-(event.data.previous.numChildren()))>0) { let msg="notification arrived" let payload = { notification: { title: 'Firebase Notification', body: msg, sound: 'default', badge: '1' […]

如何同时使用“web-push”和“fcm-push”节点包?

我一直在尝试使用Firebase云消息传递和一些节点包来设置Web推送通知服务器/客户端体系结构。 经过多个教程,我真的很困惑。 我尝试了“web-push”节点包,但它需要gcm-key,正如谷歌宣布的那样,GCM现在正在转向FCM。 所以,我看了另一个名为“fcm-push”的软件包,但它不支持VAPID。 我甚至不确定为什么VAPID需要分开。 所以,我会在这里提出一些直接的问题 – 为什么有两个单独的键,即GCM / FCM和VAPID? 一旦我从客户端获得订阅密钥到服务器,我是否需要将它们存储在数据库中? 有没有其他方法可以用来保存它们? 它看起来像“fcm-push”包不支持VAPID键,它的文档只提到它的iOS和Android。 另一方面,“web-push”包不支持FCM。 那么,我应该同时使用这两个软件包吗? 如果是的话,那么我应该依靠什么软件包来完成哪个function?

成功sendToDevice后,Firebase云消息传递不起作用

我使用Firebase云端function通过云端消息向iOS设备发送通知。 sendToDevice方法工作良好,并返回成功承诺,在Firebase函数日志中没有任何错误或警告,但在iOS上,不显示通知。 如果我通过Firebase通知信息中心发送通知,该通知很有用,并且会在设备上显示通知。 我不知道我在哪里可以有bug。 有可能是iOS应用程序端的错误,即使它像我说的那样工作? Firebaseconfiguration: var functions = require('firebase-functions'); var admin = require('firebase-admin'); var config = functions.config(); admin.initializeApp(functions.config().firebase); 部分云function: APP.services.firebase.admin.database().ref('tokens/' + userId).once('value', function(snapshot) { var userDevicesTokens = []; snapshot.forEach(function(childSnapshot) { userDevicesTokens.push(childSnapshot.key) }); if (userDevicesTokens.length === 0) { console.warn('No tokens for user'); return; } var payload = { data: { title: options.title, text: options.text, type: […]

在每次执行中发送多个推送通知的Firebase函数中返回*的内容?

我正在使用单个的Firebasefunction向我的Android用户发送多个推送通知。 每个通知的详细信息都将写入我的Firebase数据库中的date和时间。 我使用cron通过http请求来触发此Firebasefunction。 我的问题是,Firebase函数应该如何返回以完成所有Firebase节点(代表通知)的循环并完成发送所有通知? 这是我现在所拥有的。 它在发送第一个通知之后退出。 我想要的是完成查看所有Firebase子节点并为每个节点发送通知。 我不明白Promise的想法足以找出在多个推送通知的情况下返回什么。 这也没有帮助,我几乎完全忘记了如何写javascript。 exports.sendHourlyNotifications = functions.https.onRequest((req, res) => { const dateStr = req.query.date; const hourStr = req.query.hour; console.log('sendHourlyNotifications', 'date: ' + dateStr + " hour: " + hourStr); const parentRef = admin.database().ref(); const notifRef = parentRef.child('all-notifications'); const hourRef = notifRef.child(dateStr).child(hourStr); return hourRef.once('value').then(snapshot => { const updates = {}; snapshot.forEach(function(childSnapshot) […]

如何使用Cloud Functions for Firebase向特定用户发送推送通知

我使用Firebase作为我的Android应用程序的后端,并且对于使用Firebase的云端函数非常新,我想知道如何在发生事件时发送特定用户的推送通知。 例如,如果在数据库的adminName节点上发生写入时,如何在下面的代码中使用uId向用户发送推送通知: exports.sendNotification = functions.database.ref('/users/{uId}/groups/{adminName}') .onWrite(event => { // Grab the current value of what was written to the Realtime Database. var eventSnapshot = event.data; var str1 = "Author is "; var str = str1.concat(eventSnapshot.child("author").val()); console.log(str); var topic = "android"; var payload = { data: { title: eventSnapshot.child("title").val(), author: eventSnapshot.child("author").val() } }; // Send a […]

有没有办法将不同的徽章计数发送给同一主题的不同用户?

我有我的Node.js项目,我正在向IOS用户发送通知数量的FCM集成,我需要pipe理通知计数,即徽章计数,这将是不同的设备,但我发送通知给一个特定的主题,这些设备已订阅。 我的有效载荷是: var payload = { notification: { title: "Title…", body: "Notification Body…", sound: "customeSound.caf", badge : "?" }, data: { testData: "custom data" } }, topic = "topicName"; admin.messaging().sendToTopic(topic, payload) .then(function (response) { // See the MessagingTopicResponse reference documentation for the // contents of response. console.log("Successfully sent message:", response); }) .catch(function (error) { console.log("Error […]

Android在应用程序未在后台运行时发送短信

有没有什么办法使用SmsManager发送短信而无需打开应用程序。 我正在使用FirebaseMessagingService并从onMessageReceived方法得到remoteMessage包含移动否和消息。 然后我使用SmsManager发送短信。 并且我声明了清单文件中的permission.SEND_SMS/RECEIVE_SMS 。 这是我的代码: public void onMessageReceived(RemoteMessage remoteMessage){ String mobile = remoteMessage.getData().get("mobileno"); String message = remoteMessage.getData().get("message"); SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(mobile, null, message, null, null); } 它的工作时间应用程序正在运行。 但没有在应用程序不在后台运行时工作。 当应用程序没有运行时,有什么方法可以发送短信? 请帮我..谢谢…

Firebase云端function总是超时

我正在探索Firebase云计算function,并试图通过http请求发送通知。 问题是,即使我设法发送通知,请求总是超时。 这是我的脚本 const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); exports.friendRequestNotification = functions.https.onRequest((req, res) => { const senderId = req.query.senderId; const recipientId = req.query.recipientId; const getRecipientPromise = admin.database().ref(`/players/${recipientId}`).once('value'); const getSenderPromise = admin.database().ref(`/players/${senderId}`).once('value'); return Promise.all([getRecipientPromise, getSenderPromise]).then(results => { const recipient = results[0]; const sender = results[1]; const recipientToken = recipient.child("notificationsInfo/fcmToken").val(); const notificationAuthorization = recipient.child("notificationsInfo/wantsToReceiveNotifications").val(); […]