Amazon web services AWS使用React Native放大推送通知
关于如何实现推送通知,文档中似乎存在一些差异。以下是来自的RN代码: 但我们还需要将分析配置为其中的一部分,以下是从以下方面实现的: 请注意,在分析实现中,只有一个放大Amazon web services AWS使用React Native放大推送通知,amazon-web-services,react-native,aws-amplify,Amazon Web Services,React Native,Aws Amplify,关于如何实现推送通知,文档中似乎存在一些差异。以下是来自的RN代码: 但我们还需要将分析配置为其中的一部分,以下是从以下方面实现的: 请注意,在分析实现中,只有一个放大configure。但是在推送通知文档中,我们直接配置分析和推送通知,而不是放大。是哪一个 为了进一步混淆,我从一位AWS开发人员拥护者那里找到了第三种解释RN实现的方法: import { PushNotificationIOS } from 'react-native'; import Amplify from 'aws-am
configure
。但是在推送通知文档中,我们直接配置分析和推送通知,而不是放大。是哪一个
为了进一步混淆,我从一位AWS开发人员拥护者那里找到了第三种解释RN实现的方法:
import { PushNotificationIOS } from 'react-native';
import Amplify from 'aws-amplify';
import { PushNotification } from 'aws-amplify-react-native';
import aws_exports from './aws_exports';
Amplify.configure(aws_exports);
PushNotification.configure(aws_exports);
PushNotification
是从aws amplify react native
而不是aws amplify
导入的
这里完全混乱,欢迎澄清
编辑:补充说,我尝试过所有这些的各种组合,但运气不佳<代码>推送通知
似乎未定义且无法配置。//更新
更新了第一个代码段,因为我用它为一个设备注册了两个端点
//旧答案
首先,以下步骤应该有效:
import Amplify from 'aws-amplify;
import PushNotification from '@aws-amplify/pushnotification';
import awsExports from '../../../../../aws-exports';
Amplify.configure(awsExports);
// PushNotification.configure(awsExports); // registering 2 Endpoints for one device if running this line as well
然后,记得跑
npm install aws-amplify --save && npm install @aws-amplify/pushnotification --save
尤其是带有@的第二部分很重要
最后,在componentDidMount中:
PushNotification.onNotification((notification) => {
console.log('in app notification', notification);
notification.finish(PushNotificationIOS.FetchResult.NoData);
});
PushNotification.onRegister((token) => {
console.log('in app registration', token);
});
这是我的最终解决方案,与之斗争了3天。你试过使用它吗?
npm install aws-amplify --save && npm install @aws-amplify/pushnotification --save
PushNotification.onNotification((notification) => {
console.log('in app notification', notification);
notification.finish(PushNotificationIOS.FetchResult.NoData);
});
PushNotification.onRegister((token) => {
console.log('in app registration', token);
});