2

我正在使用 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);
4

1 回答 1

0

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

deviceToken通过获取from登录后,我设法使其工作AsyncStorage

如果您想保留endpointId并且只更新userId(每次只有一个用户登录 - 请记住,您可以将推送通知发送到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()调用以获得有效的活动目标端点。

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

如果你没有在你的 上设置endpointIdandendpoint属性会发生什么amplifyConfigdevice token它应该自行更新您的端点地址。您可以稍后使用用户 ID 更新您的端点Analytics.updateEndpoint({optOut: 'NONE', UserId: 'xxx'})

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

于 2019-03-06T14:27:39.693 回答