jpush / jpush-react-native

JPush's officially supported React Native plugin (Android & iOS). 极光推送官方支持的 React Native 插件(Android & iOS)。
http://docs.jiguang.cn
MIT License
1.35k stars 336 forks source link

请问如果我想在后面才会打开的界面收到自定义消息,怎么要注册监听? #466

Closed est7 closed 6 years ago

est7 commented 6 years ago

你的运行环境

win+npm5.4+nodev8.9

期望效果

告诉我们你希望达到什么效果。

实际效果

告诉我们实际是什么效果。

重现步骤

  1. ...
  2. ...
  3. ...
  4. ...

Debug logs

  1. 在example中只是对App.js调用addReceiveNotificationListener并收到了消息 2.在实际项目中,我有一个启动页,3秒后跳转到主界面,想在主界面addReceiveNotificationListener然后收到自定义消息后跳转到相应界面 3.目前的情况是在启动页addReceiveNotificationListener可以收到回调,在后续打开的主界面中却没办法收到 4.请问怎么样操作可以实现?
KenChoi1992 commented 6 years ago

你有没有调用 notifyJSDidLoad?

MegahertzCHN commented 6 years ago

iOS没有这个JPushModule.notifyJSDidLoad,怎么在后台监听点击推送的跳转?

huangminlinux commented 6 years ago

直接监听 openNotification 这个事件。

MegahertzCHN commented 6 years ago

应用进入后台再唤起,在App.js里面不走任何方法,在哪里监听呢?

MegahertzCHN commented 6 years ago

handleNotification () { if (Platform.OS === 'ios') { JPushModule.getRegistrationID((registrationId) => { console.log(registrationId) }) JPushModule.addGetRegistrationIdListener((map) => { console.log(map) })

  JPushModule.addReceiveNotificationListener(event => {
    console.log('alertContent: ' + JSON.stringify(event))
  })
  JPushModule.addOpenNotificationLaunchAppListener(map => {
    console.log('Opening notification!')
    console.log('map.uri: ' + map.uri)
    if (this.navigationRef.state.nav.index == 0) {
      console.log(map.uri)
    } else {
      this.schemeNavigate(map.uri)
    }
  })
  JPushModule.addReceiveOpenNotificationListener(map => {
    console.log('Opening notification!')
    console.log('map.extra: ' + map.uri)
  })
}
else {
  JPushModule.getInfo((map) => {
    console.log(map)
  })
  NativeModules.JPushModule.notifyJSDidLoad((resultCode) => {
    if (resultCode === 0) {
      JPushModule.getRegistrationID((registrationId) => {
        console.log('registrationId: ' + registrationId)
      })
    }
  })

  JPushModule.addReceiveOpenNotificationListener(map => {
    console.log('Opening notification!')
    console.log('map.extra: ' + map.extras)
    // JPushModule.jumpToPushActivity("SecondActivity");
    let extras = JSON.parse(map.extras)
    this.schemeNavigate(extras.uri)
  })
}

}

componentDidMount () { this.handleNotification() } 这段代码写在App.js里面,这样监听,可以吗?

huangminlinux commented 6 years ago

什么系统。

huangminlinux commented 6 years ago

参考这篇文章 https://github.com/jpush/jpush-react-native/blob/master/documents/common_problems.md#事件的解析

MegahertzCHN commented 6 years ago

iOS 9.3.4

MegahertzCHN commented 6 years ago

那篇文章我之前就看过了,我问的是既然App.js在iOS上面唤起已经不走任何方法了,例如:componentWillMount ()等,那这个监听方法写在哪里才能在App从后台唤起的时候调用

MegahertzCHN commented 6 years ago

现在的需求是App点击通知在后台唤起时候我能够拿到监听,但是在App.js什么方法都不会执行,怎么解决呀?不在后台我能够拿到监听JPushModule.addOpenNotificationLaunchAppListener,但是在后台唤起handleNotification ()我都不知道在哪里会可以调用?

huangminlinux commented 6 years ago

iOS 9 只有 receivenotification 方法,没有openNotification 方法

MegahertzCHN commented 6 years ago

JPushModule监听是在App.js做监听吗?

huangminlinux commented 6 years ago

确保事件触发之前监听就行,没有特别要求, 放到 index.js 都可以

MegahertzCHN commented 6 years ago

index.js里面我放的App.js,我从后台唤起App时候,没有调用任何App.js的方法

huangminlinux commented 6 years ago

应用唤起时是在 App.js 页面?

MegahertzCHN commented 6 years ago

是的

huangminlinux commented 6 years ago

你说唤起没回调都不执行,用demo 测试没有问题,可以参考demo