如何像LINE的通知组摘要一样(单独计数),如图1所示。 figure1:Red boxed word
以下是我编写的程序。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UNUserNotificationCenter.current().delegate = self
let videoLikeAction = UNNotificationAction(identifier: "videoLike", title: "進入APP", options: [.foreground])
let videoCommentAction = UNNotificationAction(identifier: "videoComment", title: "關掉通知", options: [])
//群組摘要設定
let hiddenPreviewsPlaceholder = "鎖屏時還有%u個%@"
let summaryFormat = "還有%u個%@"
let summaryVideoCategory = UNNotificationCategory(identifier: "Video-APNs", actions: [videoLikeAction, videoCommentAction], intentIdentifiers: [], hiddenPreviewsBodyPlaceholder: hiddenPreviewsPlaceholder, categorySummaryFormat: summaryFormat, options: [])
UNUserNotificationCenter.current().setNotificationCategories(
[photoCategory, summaryVideoCategory])
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
if granted {
DispatchQueue.main.async {
application.registerForRemoteNotifications()
}
}
}
return true
}
我写的结果如下:(组合计数)如图2所示。 figure2:Red boxed word