我正在使用 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
上设置 endpointId
和 endpoint
属性会怎样?它应该使用 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/