最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - FCM Notification Tap Not Triggering onNotificationOpenedApp Events in React Native (Except When Sent via FCM Console)

programmeradmin2浏览0评论

FCM Notification Tap Not Triggering Events in React Native (Except When Sent via FCM Console)

I've been struggling with this issue for the past week and couldn't find a fix.

Removed 'react-native-splash-screen' from the app

Problem:

  • When I send FCM notifications from my backend, they are received on the device, and tapping them opens the app.
  • However, the messaging event handlers in my React Native code (e.g., onNotificationOpenedApp and setBackgroundMessageHandler) do not trigger.
  • Strangely, if I send the notification using the Firebase Console, everything works perfectly—the events trigger as expected.

What I’ve Tried:

  • Ensured the payload structure matches Firebase’s expected format.
  • Verified that the event listeners are correctly registered.
  • Checked if the issue persists in both foreground and background states.
  • Debugged to confirm whether the app is receiving the notification data properly.

Has anyone faced a similar issue or knows what might be going wrong? Any help is appreciated!

        public static async Task<bool> SendNotificationToFCM(string fcmToken, string title, string message, string imageUrl, string amazonAffiliateUrl)
        {

            try
            {
                Dictionary<string, string> data = new Dictionary<string, string>
            {
                { "Why mobile development is hard?", "hello world!" },
                                                     };

                var fcmMessage = new Message()
                {
                    Notification = new Notification()
                    {
                        Title = title,
                        Body = message,
                        ImageUrl = imageUrl,
                    },
                    Data = data,
                    Token = fcmToken,
                    Android = new AndroidConfig()
                    {
                        Notification = new AndroidNotification()
                        {
                            Title = title,
                            Body = message,
                            ImageUrl = imageUrl,
                        },
                      //  Data = data,

                        Priority = Priority.High // Set high priority
                    }
                };

                string serializedMsg = JsonConvert.SerializeObject(fcmMessage);
                if (FirebaseApp.DefaultInstance == null)
                {
                    FirebaseApp.Create(new AppOptions()
                    {
                        Credential = GoogleCredential.FromFile(firebase-config.json")
                    });
                }

                // Send a message to the device corresponding to the provided
                // registration token.
                string response = await FirebaseMessaging.DefaultInstance.SendAsync(fcmMessage);
                // Response is a message ID string.
                Console.WriteLine("Successfully sent message: " + response);
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }

        }

now the react native code

  useEffect(() => {
    const handleNotification = async (remoteMessage) => {
      console.log("

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论