【发布时间】:2019-01-21 21:34:56
【问题描述】:
我无法在我的 firestore 文档数据库中获取新记录条目以向用户生成警报。
- IOS 应用可以毫无问题地获取和更新 Firestore 数据
- 如果我从 firebase 手动发送消息,我的应用会收到消息没有问题
- 我可以毫无错误地将我的云功能部署到 Firebase
我做错了什么?谢谢你的帮助。
let functions = require('firebase-functions')
let admin = require('firebase-admin')
admin.initializeApp(functions.config().firebase)
let db = admin.firestore()
exports.announceAlert = functions.database
.ref('/alerts/{documentId}')
.onCreate((snapshot, context) => {
let alert = snapshot.val()
sendNotification(alert)
})
function sendNotification(alert) {
let title = alert.Incident_Number
let summary = alert.Flash_Summary
let status = alert.Incident_Status
let payload = {
notification: {
title: 'Critical Incident: ' + title,
body: 'Summary: ' + summary,
sound: 'default'
}
}
console.log(payload)
let topic = "Alerts"
admin.messaging().sendToTopic(topic, payload)
}
【问题讨论】:
标签: ios swift google-cloud-firestore firebase-cloud-messaging