amazon-web-services - Pinpoint/FCM 返回未注册或过期的 token

标签 amazon-web-services firebase-cloud-messaging react-native-fcm aws-pinpoint

我正在使用 Pinpoint 通过 FCM 推送通知,但我收到了来自 AWS 的错误消息:

{
    "ApplicationId": "xxx",
    "RequestId": "yyy",
    "EndpointResult": {
        "5551212": {
            "DeliveryStatus": "PERMANENT_FAILURE",
            "StatusCode": 410,
            "StatusMessage": "{\"errorMessage\":\"Unregistered or expired token\",\"channelType\":\"GCM\",\"pushProviderStatusCode\":\"200\",\"pushProviderError\":\"InvalidRegistration\",\"pushProviderResponse\":\"{\\\"multicast_id\\\":752174934090126,\\\"success\\\":0,\\\"failure\\\":1,\\\"canonical_ids\\\":0,\\\"results\\\":[{\\\"error\\\":\\\"InvalidRegistration\\\"}]}\"}",
            "Address": "userID"
        }
    }

奇怪的是,当应用程序启动/加载时,Amplify.config 也没有调用 PushNotification.onRegister 函数:

const amplifyConfig = {
      Auth: {
        identityPoolId: POOL_ID,
        region: 'us-east-1'
      },
      Analytics: {
        AWSPinpoint: {
              appId: APP_ID,
              region: 'us-east-1',
              mandatorySignIn: false,
              endpointId: '5551212',
              endpoint: { 
                address: 'userID',
                channelType: 'GCM',
                optOut: 'NONE'
              }
        }
      }
    }

    PushNotification.onRegister(t => console.log(`Registration token: ${t}`), onRegister && onRegister());
    PushNotification.onNotification(n => (console.log(n), onNotification && onNotification(n)));
    PushNotification.onNotificationOpened(n => (console.log(n), onNotificationOpened && onNotificationOpened(n)));
    Amplify.configure(amplifyConfig);

最佳答案

编辑:您的错误似乎与无效注册 token 有关:确保端点地址与客户端应用程序通过 FCM 注册收到的注册 token 相匹配 - https://developers.google.com/cloud-messaging/http-server-ref#error-codes ).

我通过从 AsyncStorage 获取 deviceToken 设法让它在登录后工作。

如果您想保留 endpointId 并且只更新 userId(每次只有一个用户登录 - 请记住您可以向特定的 发送推送通知code>userId 可以有多个端点(设备、电子邮件、电话号码):

try {
  const deviceToken = await AsyncStorage.getItem('push_token'+aws_exports.aws_mobile_analytics_app_id)
  if (deviceToken !== null) {
    console.log('device token from AsyncStorage', deviceToken)
    Analytics.updateEndpoint({
      optOut: 'NONE',
      channelType: 'GCM',
      userId: userId,
      address: deviceToken,
    })
  }
} catch (error) {
  console.log('error retrieving device token from AsyncStorage', error)
}

或者,如果您想指定自己的 endpointId(这样您就可以在同一设备中拥有多个用户/端点):

try {
  const deviceToken = await AsyncStorage.getItem('push_token'+aws_exports.aws_mobile_analytics_app_id)
  if (deviceToken !== null) {
    console.log('device token from AsyncStorage', deviceToken)
    Analytics.configure({
      disabled: false,
      AWSPinpoint: {
        appId: aws_exports.aws_mobile_analytics_app_id,
        region: aws_exports.aws_mobile_analytics_app_region,
        endpointId: endpointId,
        endpoint: {
          address: deviceToken,
          channelType: 'GCM',
          optOut: 'NONE',
          userId: userId
        }
      }
    })
    Analytics.updateEndpoint({
      optOut: 'NONE',
    })
  }
} catch (error) {
  console.log('error retrieving device token from AsyncStorage', error)
}

首先,使用 window.LOG_LEVEL='DEBUG' 检查调试信息

然后,确保 Analytics 正常运行!在推送通知模块 ( https://aws-amplify.github.io/docs/js/push-notifications#configure-your-app ) 之前配置分析模块。你有调用 PushNotification.configure() 吗?

据我所知,您需要调用 PushNotification.onRegister() 才能获得有效的事件目标端点。

您是否在真实设备中进行测试?

如果您不在 amplifyConfig 上设置 endpointIdendpoint 属性会怎样?它应该使用 device token 自行更新您的端点地址。您稍后可以使用用户 ID Analytics.updateEndpoint({optOut: 'NONE', UserId: 'xxx'})

更新您的端点

ps.: 我有一个相关的问题,现在终于可以工作了,但是我用 Amplify CLI 设置了我的后端,所以它可能会略有不同

关于amazon-web-services - Pinpoint/FCM 返回未注册或过期的 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54931165/

相关文章:

java - 运行集成测试时,Maven Shade 插件会导致类路径上出现重复的 jar

java - 无法使用无服务器本地调用 AWS Lambda

android - 无法将推送通知提交到设备 token

firebase - 使用 Firebase 控制台发送 FCM 数据消息

amazon-web-services - 为什么不能使用提供的示例将 SSH 地形转换为 EC2 实例?

eclipse - 适用于 Eclipse 的 AWS 工具包 : Running AwsConsoleApp issue?

android - GCM API key 应该保密吗?

ios - iOS 上的 Firebase 推送通知 : FCM says token error: not registered but app gets no refreshed token

web - 在 Web 服务器上实现 Firebase 云消息传递

ios - ld : library not found for -lFirebaseCore clang: error: linker command failed with exit code 1 (use -v to see invocation)