0

在我的反应应用程序中,我正在使用这些包

"react-native-code-push": "^7.0.1",
"@react-native-community/push-notification-ios": "^1.8.0",

我遇到的问题(可能不是我理解的问题和问题)是,当我收到推送时,即使我的应用程序已关闭并且没有交互,应用程序也会调用 onNotification。这仅在 IOS 中发生。

这是我处理推送通知的代码

const _pushConfig = () => {
    PushNotification.configure({
      // (optional) Called when Token is generated (iOS and Android)
      onRegister: async function (token) {
        let pushToken = token.token
        if (Platform.OS === 'ios') {
          pushToken = await Storage.getString('IOSPushToken')
          if (!pushToken && pushToken !== '') {
            let fcmToken = await apnsToFcm(token.token)
            pushToken = fcmToken.results[0].registration_token
            await Storage.setString('IOSPushToken', pushToken)
          }
        }
        await Storage.setString('pushtoken', pushToken)
      },

      onNotification: _handleNotification,
      // (optional) Called when Registered Action is pressed and invokeApp is false, if true onNotification will be called (Android)
      onAction: function (notification) {
      },

      // (optional) Called when the user fails to register for remote notifications. Typically occurs when APNS is having issues, or the device is a simulator. (iOS)
      onRegistrationError: function (err) {
        console.error(err.message, err)
      },

      // IOS ONLY (optional): default: all - Permissions to register.
      permissions: {
        alert: true,
        badge: true,
        sound: true,
      },

      // Should the initial notification be popped automatically
      // default: true
      popInitialNotification: true,

      /**
       * (optional) default: true
       * - Specified if permissions (ios) and token (android and ios) will requested or not,
       * - if not, you must call PushNotificationsHandler.requestPermissions() later
       * - if you are not using remote notification or do not have Firebase installed, use this:
       *     requestPermissions: Platform.OS === 'ios'
       */
      requestPermissions: true,
    })
    createNotifcationChannel()
  }


const _handleNotification = async notification => {
    console.log('handle notification', notification)
    try {
      if (appState.Authorized && !notification.userInteraction) {
      }

      // reduce the number of time we need to set state
      if (notificationState.appNativeState === 'active') {
      }
     

      if (notification.userInteraction) {
        _handleNotificationFromTray(notification)
        return //handle opened from tray notification separately
      }

      if (appState.Authorized) {
      }
    } catch (ex) {
      console.debug(ex)
    }
  }

所以这是图书馆中的错误还是我做错了什么?在此先感谢您的帮助。:)

4

0 回答 0