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

时间:2017-02-01 10:55:57

标签: ios push-notification react-native onesignal

我使用OneSignal sdk进行反应原生。当应用程序处于焦点时,我尝试禁用内部警报。你知道怎么做吗?

这是我的代码:

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;
  }
  }
 });

1 个答案:

答案 0 :(得分:2)

我认为代码中的问题是您放置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)
  }