OneSignal-在打开应用程序(在前台)时不显示推送通知

时间:2018-09-27 23:12:59

标签: ios react-native push-notification apple-push-notifications onesignal

我在我的应用程序中使用react-native-onesignal,并且在不使用该应用程序(前台)的情况下,推送通知显示的时间为100%。但是,在打开应用程序时,不会显示通知,也不会触发侦听器。

  • 我正在使用通过yarn添加的OneSignal React-Native SDK v3.2.7
  • macOS版本:Mojave
  • XCode版本:9.4.1
  • 设备:运行iOS 11的Apple iPhone 6

我的代码基于RNOneSignal example的代码:

class Root extends Component {
  constructor(props) {
    super(props)
    this.onReceived = this.onReceived.bind(this)
    this.onOpened = this.onOpened.bind(this)
    this.onIds = this.onIds.bind(this)
  }
  componentWillMount() {
    console.warn(new Date())
    console.warn('componentWillMount')
    OneSignal.setLogLevel(7, 0);
    OneSignal.inFocusDisplaying(2);
    OneSignal.init(MY_APP_ID);
    OneSignal.configure({});
    OneSignal.addEventListener('received', this.onReceived);
    OneSignal.addEventListener('opened', this.onOpened);
    OneSignal.addEventListener('ids', this.onIds);
  }

  componentWillUnmount() {
    console.warn('componentWillUnmount')
    OneSignal.removeEventListener('received', this.onReceived);
    OneSignal.removeEventListener('opened', this.onOpened);
    OneSignal.removeEventListener('ids', this.onIds);
  }

  onReceived(notification) {
    console.warn("Notification received: ", notification);
  }

  onOpened(openResult) {
    console.warn('Message: ', openResult.notification.payload.body);
    console.warn('Data: ', openResult.notification.payload.additionalData);
    console.warn('isActive: ', openResult.notification.isAppInFocus);
    console.warn('openResult: ', openResult);
  }

  onIds(device) {
    console.warn('Device info: ', device);
  }
    render(){
        return(
            <Provider store={store}>
                <App />
            </Provider>
        );
    }
}

PS::当我在RNOneSignal example app上使用相同的应用程序ID时,一切正常(在后台和前台都显示通知)

0 个答案:

没有答案