簡體   English   中英

如何使用iOS 9在應用程序前景swift 2時標記通知

[英]How to banner notification when application foreground swift 2 with iOS 9

當應用程序停留在后台(遠程通知)時,它工作正常。 問題是我和我的一個朋友聊天的時候。 來自其他聯系人的新消息我需要像Facebook Messenger一樣顯示iOS通知警報橫幅。 還有我的設備通知列表中提供的通知。 我無法弄清楚怎么能這樣做..

喜歡這個圖像 當您的應用程序處於打開狀態並位於前台時,我找到了一個已解答的顯示iOS通知橫幅? 但它是iOS 10。 我需要支持最低iOS 9,項目是swift 2

將completionHandler行添加到appDelegate方法解決了我的問題:

//Called when a notification is delivered to a foreground app.
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
print("User Info = ",notification.request.content.userInfo)

completionHandler([.alert, .badge, .sound])
} 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM