【问题标题】:How do I disable system created notifications when my app is in the foreground?当我的应用程序在前台时,如何禁用系统创建的通知?
【发布时间】:2018-08-12 02:46:11
【问题描述】:

我在 react native 的一件小事上需要帮助。 . .

如果应用程序打开,甚至可以启用/禁用系统通知警报吗?就我而言,我在应用程序中实现了一个内部通知系统,因此如果应用程序打开,用户不希望系统通知弹出。 (我正在使用 react-native-firebase 进行通知)

【问题讨论】:

    标签: react-native react-native-firebase


    【解决方案1】:

    您可以使用 React Natives 自己的 AppState api 来确定应用程序是否在前台 (appState = active) 并以编程方式使用它来确定是否显示通知。

    使用notification 属性发送的 FCM 消息由操作系统自动处理 - 您可以切换到仅数据 FCM 消息,然后根据您的数据属性以编程方式创建和显示(如果应用程序未激活)您的通知。

    【讨论】:

    • 应用终止时不会评估仅数据通知
    【解决方案2】:

    对于 安卓

    <meta-data android:name="com.dieam.reactnativepushnotification.notification_foreground" android:value="false"/>
    

    iOS

    // Called when a notification is delivered to a foreground app.
    -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
    {
        completionHandler(UNNotificationPresentationOptionNone);
    }
    

    应用在前台时不会显示弹窗。

    【讨论】:

      猜你喜欢
      • 2018-05-31
      • 2018-11-08
      • 2018-05-04
      • 1970-01-01
      • 1970-01-01
      • 2018-06-15
      • 1970-01-01
      • 1970-01-01
      • 2017-06-26
      相关资源
      最近更新 更多