React Native iOS,前台通知不起作用

Posted

技术标签:

【中文标题】React Native iOS,前台通知不起作用【英文标题】:React Native iOS, foreground notification not working 【发布时间】:2017-10-25 14:34:41 【问题描述】:

我使用react-native-firebase 进行 FCM,当应用程序在后台通知弹出窗口中运行时正确显示。但是当应用程序在前台运行时,不会显示任何通知。相同的代码适用于android。使用下面的代码

this.firebase.messaging().createLocalNotification(

       title: 'Messenger',     
        body: "message",
        icon: 'ic_launcher',
        id: new Date().getTime()+"",
        action: action,
        screen: screen,
        local_notification: true,
        show_in_foreground: true,
        _notificationType: 'local_notification',
        opened_from_tray: false

   );

【问题讨论】:

【参考方案1】:

作为来自 react-native-fcm 模块的有效负载必须包含以下键值对。


        id: "UNIQ_ID_STRING",                               // (optional for instant notification)
        title: "My Notification Title",                     // as FCM payload
        body: "My Notification Message",                    // as FCM payload (required)
        sound: "default",                                   // as FCM payload
        priority: "high",                                   // as FCM payload
        click_action: "ACTION",                             // as FCM payload
        badge: 10,                                          // as FCM payload ios only, set 0 to clear badges
        number: 10,                                         // Android only
        ticker: "My Notification Ticker",                   // Android only
        auto_cancel: true,                                  // Android only (default true)
        large_icon: "ic_launcher",                           // Android only
        icon: "ic_launcher",                                // as FCM payload, you can relace this with custom icon you put in mipmap
        big_text: "Show when notification is expanded",     // Android only
        sub_text: "This is a subText",                      // Android only
        color: "red",                                       // Android only
        vibrate: 300,                                       // Android only default: 300, no vibration if you pass 0
        group: "group",                                     // Android only
        picture: "https://google.png",                      // Android only bigPicture style
        ongoing: true,                                      // Android only
        my_custom_data:'my_custom_field_value',             // extra data you want to throw
        lights: true,                                       // Android only, LED blinking (default false)
        show_in_foreground                                  // notification when app is in foreground (local & remote)
    

必须提供“show_in_foreground”,以便在您的应用运行时在前台显示本地通知。

【讨论】:

是的,应该设置为 true。 它只设置为真,但通知不显示在前台 您是否在 AppDelafate.m 文件中实施了此方法 `` -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification [RNFirebaseMessaging didReceiveLocalNotification:notification]; ``` 是的,已经在那里了。 -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification [RNFirebaseMessaging didReceiveLocalNotification:notification]; 在通知负载中尝试这个键值。 content_available:真,show_in_foreground:真,优先级:“高”

以上是关于React Native iOS,前台通知不起作用的主要内容,如果未能解决你的问题,请参考以下文章

React Native Push Notifications 在 Android 中不起作用,但在 iOS 上运行良好

React-native-firebase Bigimage 在 ios 中不起作用

重复本地通知在 react-native-push-notification 中不起作用

如何在 IOS react native 上接收推送通知?

当我的 iOS 应用程序处于前台时,如何使本地通知静音?

React-native:使用 zo0r/react-native-push-notification 显示前台通知,例如后台通知