这是我创建本地通知的方法,该通知会在3秒后成功显示
let content = UNMutableNotificationContent()
content.title = "Test"
content.body = "Test"
content.categoryIdentifier = "UYLReminderCategory"
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 3,
repeats: false)
let identifier = "UYLLocalNotification"
let request = UNNotificationRequest(identifier: identifier,
content: content, trigger: trigger)
let snoozeAction = UNNotificationAction(identifier: "Snooze",
title: "Snooze", options: [])
let deleteAction = UNNotificationAction(identifier: "UYLDeleteAction",
title: "Delete", options: [.destructive])
let category = UNNotificationCategory(identifier: "UYLReminderCategory",
actions: [snoozeAction,deleteAction],
intentIdentifiers: [], options: [])
center.setNotificationCategories([category])
center.add(request, withCompletionHandler: { (error) in
if let error = error {
// Something went wrong
}
})
,但是它会在几秒钟后隐藏起来,是否有可能防止它隐藏起来,就像在“警报”应用程序中内置的苹果一样。 谢谢。