【问题标题】:How to show firebase notifications when application is in foreground当应用程序在前台时如何显示firebase通知
【发布时间】:2018-11-08 03:26:52
【问题描述】:

我正在使用 firebase 进行推送通知。我想在应用程序处于前台时向用户显示通知。

应用程序关闭时通知工作正常。但即使应用程序处于活动状态,我也想显示一个股票 iOS 通知横幅。

我参考了以下链接:

Displaying a stock iOS notification banner when your app is open and in the foreground?

我想以与上面链接所示完全相同的方式显示通知。

这两种方法我已经实现了:

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {

        completionHandler(.alert)
    }

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

      completionHandler()
}

谁能给我一个当应用程序在前台时显示推送通知的代码示例?

【问题讨论】:

  • @Sh_Khan 我知道,但我怎样才能做到这一点?
  • 试图在应用打开时发送推送? , 你当前的代码也没有编译尝试过什么答案?
  • 在前台,检测到didRecieveRemoteNotification中的远程通知并发送本地通知
  • 您的问题与 Firebase 无关

标签: ios swift firebase push-notification firebase-cloud-messaging


【解决方案1】:

你可以试试

@available(iOS 10, *)

    extension AppDelegate : UNUserNotificationCenterDelegate {

    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                willPresent notification: UNNotification,
                                withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {

          completionHandler([.alert, .sound])

    }

}

更多信息请点击此处Notifications

【讨论】:

    【解决方案2】:

    你可以调用这个函数,用于推送通知:

    func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]){
         print("\(userInfo)")
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-12
      • 2020-01-27
      • 1970-01-01
      • 1970-01-01
      • 2016-11-21
      • 1970-01-01
      • 2021-12-13
      相关资源
      最近更新 更多