react-native Android使用极光推送

极光推送注册登陆完>>>点击右上角的应用管理>>>然后点击创建应用>>>拿到应用包名和AppKey

基础配置就按照官网的配置就好了
https://www.npmjs.com/package/jpush-react-native

JPUSH_CHANNEL配置一般直接是“default”

切记包名改成极光推送上面的之后,其他地方的包名也要保持一致,不然会报错
然后就可以测试了

import JPush from 'jpush-react-native';//极光推送
import Config from "react-native-config"; // 这是区分开发和线上版本的插件
省略...
componentDidMount() {
    console.log('a')
    this.props.navigation.dispatch(resetAction)
    JPush.init(result => {
      console.log('inti', result)
    });
    //连接状态
    this.connectListener = result => {
      console.log("connectListener:" + JSON.stringify(result))
    };
    JPush.addConnectEventListener(this.connectListener);
    //通知回调
    this.notificationListener = result => {
      this.navigation.navigate('Datamonitoring')
      console.log("notificationListener:" + JSON.stringify(result))
    };
    JPush.addNotificationListener(this.notificationListener);
    //本地通知回调
    this.localNotificationListener = result => {
      console.log("localNotificationListener:" + JSON.stringify(result))
    };
    JPush.addLocalNotificationListener(this.localNotificationListener);
    //自定义消息回调
    this.customMessageListener = result => {
      console.log("customMessageListener:" + JSON.stringify(result))
    };
    // 指定推送用户 我这里的user是区别开发和线上,使用的是react-native-config插件
    JPush.setAlias({ sequence: 2, alias: String(Config.SET_ALIAS + '_user') })
    JPush.addCustomMessagegListener(this.customMessageListener);
    //tag alias事件回调
    this.tagAliasListener = result => {
      console.log("tagAliasListener:" + JSON.stringify(result))
    };
    JPush.addTagAliasListener(this.tagAliasListener);
    //手机号码事件回调
    this.mobileNumberListener = result => {
      console.log("mobileNumberListener:" + JSON.stringify(result))
    };
    JPush.addMobileNumberListener(this.mobileNumberListener);

    // 安卓监听返回按钮事件
    if (Platform.OS === 'android') {
      console.log('进来了')
      BackHandler.addEventListener('hardwareBackPress', this.onBackPress);
    }
  }

在这里插入图片描述
在这里插入图片描述
这里是选择设备别名来发送,设备别名为user可以接收到通知,也可以广播所有人但是有次数限制!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值