Reactnative IOS Pushotification/PushNotificationIOS onNotification 收到通知时不会直接调用

发布于 2025-01-09 05:54:58 字数 1586 浏览 4 评论 0原文

我使用了reactnative PushNotification/PushNotificationIOS模块,我的问题是当我的设备IOS在前台收到通知时,函数 onNotification: function(notification) {} 不直接调用,仅通过点击调用。 我想直接获取通过 pububnub 控制台发送的数据通知 paylaod,无需任何用户交互,此功能在 android 中运行良好,但 ios 并非全部。 控制台没有显示任何内容可以帮助我解决这个问题,谢谢。

这是函数和导入模块:

import PushNotification from "react-native-push-notification";
import PushNotificationIOS from "@react-native-community/push-notification-ios";

onNotification: function(notification) {
if (Platform.OS=='ios')
{

  console.log('notif',notification)

 
notification.finish(PushNotificationIOS.FetchResult.NoData);

},
 
    onAction: function (notification) {
  
    },
   
    onRegistrationError: function(err) {
  
    },
  permissions: {
      alert: true,
      badge: true,
      sound: true,
    },
   popInitialNotification: true,
    requestPermissions: true,
    senderID: FIREBASE_SENDER_ID,
})
}

这是要发送的对象 pubnub :

{"pn_apns":{
      "aps":{
        "alert": {
            "body": "Course disponible",
            "title": "My course"
        },
        "sound": "beep.wav",
            
"data": { "reference": "ND1004332", "startstation": ""  }
          },


      "pn_push":[
         {
            "push_type":"alert",
            "auth_method":"token",
            "targets":[
               {
                  "environment":"development",
                  "topic":"com.test.fr"
               }
            ],
            "version":"v2"
         }
      ]

}
      
}  

I used reactnative PushNotification/PushNotificationIOS modules , My issue is when notification received on foreground to my device IOS ,the function onNotification: function(notification) {} does not called directly is called by click only .
I want to fetch data notification paylaod sent via pububnub console directly without any user interaction ,this function is working fine in android but ios not all.
the console does not show anything can help me to solve this issue and thanks.

This the function and imports module:

import PushNotification from "react-native-push-notification";
import PushNotificationIOS from "@react-native-community/push-notification-ios";

onNotification: function(notification) {
if (Platform.OS=='ios')
{

  console.log('notif',notification)

 
notification.finish(PushNotificationIOS.FetchResult.NoData);

},
 
    onAction: function (notification) {
  
    },
   
    onRegistrationError: function(err) {
  
    },
  permissions: {
      alert: true,
      badge: true,
      sound: true,
    },
   popInitialNotification: true,
    requestPermissions: true,
    senderID: FIREBASE_SENDER_ID,
})
}

and this the object pubnub to send :

{"pn_apns":{
      "aps":{
        "alert": {
            "body": "Course disponible",
            "title": "My course"
        },
        "sound": "beep.wav",
            
"data": { "reference": "ND1004332", "startstation": ""  }
          },


      "pn_push":[
         {
            "push_type":"alert",
            "auth_method":"token",
            "targets":[
               {
                  "environment":"development",
                  "topic":"com.test.fr"
               }
            ],
            "version":"v2"
         }
      ]

}
      
}  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雅心素梦 2025-01-16 05:54:58
import {Platform} from 'react-native';
import PushNotification from 'react-native-push-notification';
import PushNotificationIOS from "@react-native-community/push-notification-ios"; 
if (Platform.OS === 'ios') {
// Must be outside of any component LifeCycle (such as `componentDidMount`).
PushNotification.configure({
    onNotification: function (notification) {
        console.log("NOTIFICATION:", notification);
        const { foreground, userInteraction, title, message } = notification;
        if (foreground && (title || message) && !userInteraction) PushNotification.localNotification(notification);
        notification.finish(PushNotificationIOS.FetchResult.NoData);
    },

    permissions: {
        // alert: true,
        // badge: true,
        sound: true
      },
});
}
import {Platform} from 'react-native';
import PushNotification from 'react-native-push-notification';
import PushNotificationIOS from "@react-native-community/push-notification-ios"; 
if (Platform.OS === 'ios') {
// Must be outside of any component LifeCycle (such as `componentDidMount`).
PushNotification.configure({
    onNotification: function (notification) {
        console.log("NOTIFICATION:", notification);
        const { foreground, userInteraction, title, message } = notification;
        if (foreground && (title || message) && !userInteraction) PushNotification.localNotification(notification);
        notification.finish(PushNotificationIOS.FetchResult.NoData);
    },

    permissions: {
        // alert: true,
        // badge: true,
        sound: true
      },
});
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文