RN 集成极光推送 jpush-react-native

jpush-react-native —-是极光推送官方开发的 React Native 版本插件,可以快速集成推送功能。

import JPushModule from 'jpush-react-native';
if (Platform.OS === 'android') {
// 通知 JPushModule 初始化完成,发送缓存事件。
     JPushModule.notifyJSDidLoad((resultCode) => {

     });
}
// 接收自定义消息事件
JPushModule.addReceiveCustomMsgListener((message) => {
    console.log("用户点击打开了,removeReceiveCustomMsgListener");
});
// 接收推送事件
JPushModule.addReceiveNotificationListener((message) => {
    console.log("next removeReceiveNotificationListener: " + message);
    DeviceEventEmitter.emit('hasNewNotice', '通知来了');
});

// 点击推送事件,打开通知
JPushModule.addReceiveOpenNotificationListener((map) => {
   console.log("next removeReceiveOpenNotificationListener ,map.extra: " + map.extras);
   // 可执行跳转操作,也可跳转原生页面
   // this.props.navigation.navigate("SecondActivity");
});

//移除监听消息通知
removeReceivedJPush() {
   JPushModule.removeReceiveCustomMsgListener();
   JPushModule.removeReceiveNotificationListener();
   JPushModule.removeReceiveOpenNotificationListener();
   // 清除所有通知
   JPushModule.clearAllNotifications()
}

参考地址:https://github.com/jpush/jpush-react-native#api

猜你喜欢

转载自blog.csdn.net/snow51/article/details/80843409
今日推荐