firebase - 使用 Firebase 进行通知,获取 `app instance has been unregistered`

标签 firebase go firebase-cloud-messaging firebase-admin

尝试使用 Firebase 进行跨平台移动通知。获取设备 token 的客户端代码似乎有效,因为我们可以从 Firebase Web 控制台发送通知。但我不知道如何从我们的服务器发送通知。我们收到错误:app 实例已被取消注册;代码:注册 token -未注册;详细信息:在以下 Go 代码片段中调用 messagingClient.Send 时未找到请求的实体:

    ctx := r.Context()
    opt := option.WithCredentialsFile("serviceAccountKey.json")
    app, err := firebase.NewApp(context.Background(), nil, opt)
    if err != nil {
      return err
    }

    // Obtain a messaging.Client from the App.
    messagingClient, err := app.Messaging(ctx)
    if err != nil {
      return err
    }
    // See documentation on defining a message payload.
    message := &messaging.Message{
      Notification: &messaging.Notification{
        Title: "Notification title",
        Body:  "Notification body",
      },
      Token: myDeviceToken,
    }

    // Send a message to the device corresponding to the provided
    // registration token.
    response, err := messagingClient.Send(ctx, message)
    if err != nil {
      return err
    }

我们使用的凭据文件来自 Firebase 控制台,位于“设置”、“服务帐户”、“Firebase 管理 SDK”下。

最佳答案

根据documentation for FCM error codes ,注册 token 未注册意味着:

The provided registration token is not registered. A previously valid registration token can be unregistered for a variety of reasons, including:

  • The client app unregistered itself from FCM.
  • The client app was automatically unregistered. This can happen if the user uninstalls the application or, on iOS, if the APNS Feedback Service reported the APNS token as invalid.
  • The registration token expired. For example, Google might decide to refresh registration tokens or the APNS token may have expired for iOS devices.
  • The client app was updated, but the new version is not configured to receive messages.

For all these cases, remove this registration token and stop using it to send messages.

鉴于这里有多种可能性,我们实际上不可能说出它是哪一种。如果您需要 FCM 故障排除方面的帮助,请contact Firebase support directly任何人都可以采取准确的步骤来重现该问题。

关于firebase - 使用 Firebase 进行通知,获取 `app instance has been unregistered`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58308835/

相关文章:

java - Firebase 实时数据库通常是如何收费的?

go - 如何在 Go 中添加两个任意大数?

node.js - messages.sendMulticast 不是一个函数

swift 4 : Having different values to each CollectionView Items

java - firebase recyclerview 上的 "No such Method error"

html - 如何在 GO、Google App Engine 中解析 HTML 模板

Go:使用 bindata 嵌入 JS 文件

android - 在 Android 后台和使用 FCM 时处理 keepSynced()

ios - FCM UserInfo,如何向下钻取它的值(value)?

android - “无法联系 Firebase 服务器”