代码之家  ›  专栏  ›  技术社区  ›  user6354073

使用Firebase云函数iOS推送通知

  •  2
  • user6354073  · 技术社区  · 7 年前

    尝试通过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.")
                }
            });
        }); 
    
    1 回复  |  直到 7 年前
        1
  •  4
  •   Doug Stevenson    7 年前

    你需要 integrate FCM into your iOS app . 注意以下部分 receiving the current registration token .

    注册令牌通过firmessagingdegate方法传递 消息:didReceiveRegistrationToken:。调用此方法 通常每个应用程序使用FCM令牌启动一次。当此方法为 这是一个理想的时间:

    • 如果注册令牌是新的,请将其发送到应用程序服务器(建议实现服务器逻辑以确定 令牌是新的)。
    • 向主题订阅注册令牌。只有在新订阅或用户 重新安装应用程序。

    因此,您必须在应用程序中获取该令牌,将其存储在云功能可以获取的位置(传统上是实时数据库),并在功能运行时查询该令牌。