OGeek|极客世界-中国程序员成长平台

标题: ios:当应用程序处于焦点时禁用警报通知(OneSignal) [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 12:48
标题: ios:当应用程序处于焦点时禁用警报通知(OneSignal)

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

这是我的代码:

OneSignal.configure({
onIdsAvailable: function (device) {
  console.log('UserId = ', device.userId);
 console.log('ushToken = ', 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;
  }
  }
 });



Best Answer-推荐答案


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

关于ios:当应用程序处于焦点时禁用警报通知(OneSignal),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41977942/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4