ios:应用处于焦点时禁用警报通知(OneSignal)

ios: disable alert notification when app in focus (OneSignal)

我将 OneSignal sdk 用于 React Native。当应用程序处于焦点时,我尝试禁用内部警报。你知道怎么做吗?

这是我的代码:

OneSignal.configure({
onIdsAvailable: function (device) {
  console.log('UserId = ', device.userId);
 console.log('PushToken = ', device.pushToken);
 getUserId(device.userId);
 },
 onNotificationReceived: function (notification) {
OneSignal.checkPermissions((permissions) => {
  console.log(permissions);
 });
OneSignal.inFocusDisplaying(0);
},
onNotificationOpened: function(message, data, isActive) {
 console.log("MS TYPE", message);
 switch(message.notification.payload.additionalData.type) {
 case '1':
       Actions.messenger({id:     message.notification.payload.additionalData.userID});
    break;
case '2':
      Actions.overview();
    break;
  }
  }
 });

我认为您代码中的问题在于您放置 OneSignal.inFocusDisplaying(0);

的位置

你需要像

一样把它放在componentWillMount
  componentWillMount () {
    OneSignal.addEventListener('received', this.onReceived.bind(this))
    OneSignal.addEventListener('opened', this.onOpened)
    OneSignal.addEventListener('registered', this.onRegistered)
    OneSignal.addEventListener('ids', this.onIds.bind(this))

    // Set inFocusDisplaying to prevent the default push notification alert when the is in focus
    // Android ONLY
    OneSignal.inFocusDisplaying(0)
  }