问题描述
我正在将推送通知从 AWS Pinpoint 发送到我的 react-native 应用程序。如果我使用 aws amplify CLI 在线开发 AWS 指南中提到的一个新的 react-native 应用程序并创建全新的设置,它工作正常。但问题是我已经在我的本机应用程序中使用 Auth 进行了放大设置。现在我需要将 PUSH NOTIFICATION 集成到我现有的 react-native 应用程序中。如何在已配置 AWS AUTH 的现有 react-native 应用程序中使用 AWS PINPOINT 添加推送通知。
以下是我尝试过的。
- 创建 Firebase 项目并在 Android 中添加所需的 Android 依赖项和配置。
- 保存了 AWS Pinpoint 推送通知所需的 API 服务器密钥。
- 创建了 AWS Pinpoint 项目并在推送通知中添加了 FCM 通道。
- 在我的本机反应应用中添加到分析配置下方。
react-native 中的配置:
-webkit-scroll-snap-align: start;
scroll-snap-align: start;
我的应用运行良好。但是当我尝试从 AWS CLI 控制台发送通知时,我收到错误
Amplify.configure({
Auth: {
// required only for Federated Authentication - Amazon Cognito Identity Pool ID
identityPoolId: 'ap-XXXXXX',// required - Amazon Cognito Region
region: 'ap-XXXXX',// OPTIONAL - Amazon Cognito Federated Identity Pool Region
// required only if it's different from Amazon Cognito Region
identityPoolRegion: 'ap-XXXX',// OPTIONAL - Amazon Cognito User Pool ID
userPoolId: 'ap-XXXXX',// OPTIONAL - Amazon Cognito Web Client ID (26-char alphanumeric string)
userPoolWebClientId: 'XXXXXXX',},Analytics: {
AWSPinpoint: {
// OPTIONAL - Amazon Pinpoint App Client ID
appId: 'XXXXX',// OPTIONAL - Amazon service region
region: 'us-west-2',// OPTIONAL - Customized endpoint
//endpointId: 'XXXXXXXXXXXX',// OPTIONAL - Default Endpoint information
endpoint: {
// address: 'xxxxxxx',// The unique identifier for the recipient. For example,an address Could be a device token,email address,or mobile phone number.
attributes: {
hobbies: ['piano','hiking'],channelType: 'GCM',// The channel type. Valid values: APNS,GCM
// Customized userId
//userId: 'XXXXXXXXXXXX',// User attributes
//userAttributes: {
// interests: ['football','basketball','AWS']
// ...
//}
},}
},});
PushNotification.onNotification((notification) => {
console.log('in app notification',notification);
});
// get the registration token
// This will only be triggered when the token is generated or updated.
PushNotification.onRegister((token) => {
console.log('in app registration',token);
});
// get the notification data when notification is opened
PushNotification.onNotificationopened((notification) => {
console.log('the notification is opened',notification);
});
Analytics.getPluggable('AWSPinpoint')._config.endpointId;
//above give me the endpoint.
我是 AWS 的新手,有点卡在这里。我已经花了一整天的时间,但找不到问题所在。有什么我遗漏的吗??
请帮帮我。
谢谢, 穆尼什
解决方法
不知何故,当 PushNotification onRegister 方法被调用时,我没有得到 deviceToken/Endpoint。可能是 Pinpoint 未填充 Firebase 端点/令牌的原因。所以我不得不通过传递令牌手动使用 updateEndpoint。所以我尝试在我的项目中使用 firebase 并尝试获取令牌。我将相同的内容传递给 Analytics updateEndpoint,它对我有用。基本上我没有调用 updateEndpoint,因为我没有有效的端点可以更早地传入。
如果将来有人遇到困难,请发布此信息。谢谢