【问题标题】:ios: disable alert notification when app in focus (OneSignal)ios:当应用程序处于焦点时禁用警报通知(OneSignal)
【发布时间】:2017-02-01 10:55:56
【问题描述】:

我使用 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;
  }
  }
 });

【问题讨论】:

    标签: ios push-notification react-native onesignal


    【解决方案1】:

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

    你需要把它放在componentWillMountlike

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

    【讨论】:

    • 自 4.0 版以来已更改。现在应该调用OneSignal.disablePush(boolean),因为inFocusDisplaying 已从新api 中删除
    • 好的@pavle 你能否更新答案,因为我已经切换到 Flutter 多年了:D
    猜你喜欢
    • 1970-01-01
    • 2021-12-13
    • 2017-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多