jpush-react-native addGetRegistrationIdListener 不执行

honestxll
2018-04-24 03:12 3.5k 0

如题,安卓部分,已经可以跑通了,但是 ios 部份接收不到通知,我想试试看能过 registrationId 的方式看看能不能收到通知,结果发现 registrationId 获取不到。

接入过程

我是按照 jpush-react-nativegithub 介绍来操作的,后台用的 nodejsjpush-sdk。证书啥的也都弄好了,运行 app 的时候还会提示是否需要开启通知,Token Authentication证书 推送我也都试过了:(

代码

// react native 代码
  componentDidMount() {
    if (Platform.OS === 'android') {
      JPushModule.initPush();
    } else {
      JPushModule.setupPush();
    }
    JPushModule.setAlias(this.state.alias, () => {
      console.log('成功设置 alias');
    }, () => {
      console.log('设置 alias 失败');
    });
    JPushModule.addReceiveCustomMsgListener((ret) => {
      const data = JSON.parse(ret.extras);
      this.setState({ id: data.id });
    });
    JPushModule.addReceiveNotificationListener(() => {});
    JPushModule.addReceiveOpenNotificationListener(() => {
      this.props.navigation.navigate('Article', { id: this.state.id, type: '推荐' });
    });
    JPushModule.addGetRegistrationIdListener((registrationId) => {
      console.log(`Device register succeed, registrationId ${registrationId}`);
    }, (error) => {
      console.error(`获取不到`, error);
    });
  }
// nodejs 部分
    client.push().setPlatform(JPush.ALL)
      .setAudience(JPush.ALL, JPush.alias('reactnative'))
      .setNotification(data.title, JPush.ios('ios alert', data.title, 5))
      .setMessage('ok', data.title, 'obj', { id: data.id })
      .send(function(err, res) {
        if (err) {
          console.log(err.message);
        } else {
          console.log('Sendno: ' + res.sendno);
          console.log('Msg_id: ' + res.msg_id);
        }
      });

2个回答

热门排序