【发布时间】:2018-07-17 12:53:29
【问题描述】:
我在我的聊天应用程序中使用 firebase 通知,并将其发送到我的设备。我的问题是如何在特定视图控制器上隐藏远程通知。当应用程序在前台时,我正在使用
UNUserNotificationCenter,将呈现委托方法
显示横幅,但是当我在 chatViewController 中时,我不想显示通知横幅、声音、警报等我想要的应用程序功能......对不起我的英语
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo:[AnyHashable:Any] = notification.request.content.userInfo
print("\(userInfo)")
completionHandler([.alert, .badge, .sound])
}
【问题讨论】:
-
查看
UNNotificationPresentationOptions的所有值。应该有一个.none(Objective-C 中的UNNotificationPresentationOptionNone)。当您决定不想显示它时,在completionHandler()中使用它。但是,知道当前向用户呈现的是哪个 ViewController 是另一个问题(并且取决于您的应用架构)。 -
所以在伪代码中:
if showAlert {completionHandler([.alert, .badge, .sound]} else {completionHandler([.none])} -
标签: ios swift3 push-notification swift4