Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services Pinpoint/FCM返回未注册或过期的令牌_Amazon Web Services_Firebase Cloud Messaging_React Native Fcm_Aws Pinpoint - Fatal编程技术网

Amazon web services Pinpoint/FCM返回未注册或过期的令牌

Amazon web services Pinpoint/FCM返回未注册或过期的令牌,amazon-web-services,firebase-cloud-messaging,react-native-fcm,aws-pinpoint,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": "{\"

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

编辑:您的错误似乎与无效的注册令牌有关:确保端点地址与客户端应用通过向FCM-注册收到的注册令牌匹配

通过从
AsyncStorage
获取
deviceToken
,我成功地使它在登录后工作

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

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


首先,使用
window.LOG\u LEVEL='debug'

然后,确保分析工作正常!在推送通知模块()之前配置分析模块。您是否调用了
PushNotification.configure()

据我所知,您需要调用
PushNotification.onRegister()
,以获取有效的活动目标端点

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

如果不在
config
上设置
endpointId
endpoint
属性,会发生什么?它应该自己用
设备令牌
更新您的端点地址。您可以稍后使用用户id
Analytics.updateEndpoint({optOut:'NONE',UserId:'xxx'})更新端点。


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

您解决过这个问题吗?没有。。。仍在与此抗争…对此有任何更新吗???我最终编写了一个模块来直接检索令牌。嗨,我尝试直接从Firebase获取令牌,登录后,我使用deviceToken更新端点,配置如下:```等待分析。更新点({//地址:fcmToken,通道类型:“GCM”,userId:uid,optOut:'NONE',});`它似乎起了作用,我能够向我的设备发送推送通知。大约20分钟后,如果我尝试推送通知,我会收到以下错误:“StatusCode”:410,“StatusMessage”:“{\“errorMessage\”:\“未注册或过期的令牌知道其原因吗?如果我删除以下endpointId:'5551212',endpoint:{address:'userID',channelType:'GCM',optOut:'NONE'}它注册设备ID,我可以发送给它,但我不能在updateEndpoint函数调用中指定endpointId。哦,为了回答您的其他问题,我调用PushNotification.configure(),是的,我正在用一台真正的设备进行测试。我的难题是,我想发送一个端点ID,或者其他标识符,而不是设备ID,因为一台设备上会有多个用户。嘿@PatrickDench我改进了我的答案,你现在能检查一下它是否对你有帮助吗?我来看看-我暂时用RN模块破解了一个工作。很好讨厌,但是。。。
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)
}
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)
}