【问题标题】:Push notifications using Firebase Cloud Function iOS使用 Firebase Cloud Function iOS 推送通知
【发布时间】:2018-06-20 05:51:42
【问题描述】:

尝试通过 Firebase 云功能发送远程推送通知。我一直关注的资源通过sendToDevice 方法实现了这一点,该方法将字符串作为参数。来自 GitHub 的资源称其为“设备通知令牌”,当用户同意在应用程序中接收通知时会检索该令牌。 Firebase 称其为“来自客户端 FCM SDK 的注册令牌”。这里的输入应该是什么,以及如何检索它?

      // Send notification to device via firebase cloud messaging.  
      // https://firebase.google.com/docs/cloud-messaging/admin/send-messages
      // https://github.com/firebase/functions-samples/blob/master/fcm-notifications/functions/index.js
      // 

      admin.messaging().sendToDevice(request.query.tokenId, payload).then(response => {
        response.results.forEach((result, index) =>  {
            const error = result.error 
            if (error) {
                console.log("Failure sending notification.")
            }
        });
    }); 

【问题讨论】:

    标签: node.js firebase firebase-cloud-messaging google-cloud-functions


    【解决方案1】:

    您需要integrate FCM into your iOS app。关注receiving the current registration token部分。

    注册令牌通过 FIRMessagingDelegate 方法传递 消息传递:didReceiveRegistrationToken:。这个方法被称为 通常每个应用程序以 FCM 令牌开始一次。当这个方法是 调用,现在是理想的时间:

    • 如果注册令牌是新的,发送到你的应用服务器(建议实现服务器逻辑来判断是否 令牌是新的)。
    • 为主题订阅注册令牌。仅在新订阅或用户拥有 重新安装了该应用。

    因此,您必须在应用中获取此令牌,将其存储在 Cloud Function 可以获取的某个位置(传统上是实时数据库),并在函数运行时查询它。

    【讨论】:

    • 我相信 Android 客户端也需要按照以下链接执行相同的步骤:firebase.google.com/docs/cloud-messaging/android/client 或者是否有任何差异需要注意?
    • 我不这么认为。
    • 你能否深入解释一下这部分[接收当前注册令牌。]我不明白它
    • 此注册令牌是否过期?如果我将它存储到数据库并从那里读取通知,它会在以后更改吗?
    猜你喜欢
    • 1970-01-01
    • 2018-06-18
    • 2019-01-30
    • 2016-11-21
    • 2017-11-16
    • 2018-09-11
    • 1970-01-01
    相关资源
    最近更新 更多