Schließen der Meldung in 20 Sekunden:
if #available(iOS 10.0, *) {
... <setting up an iOS 10 notification content and trigger>
notificationCenter.add(UNNotificationRequest(identifier: "myidentifier",
content: content,
trigger: trigger))
Timer.scheduledTimer(timeInterval: 20.0,
target: self,
selector: #selector(self.cancelDeliveredNotification),
userInfo: nil,
repeats: false)
} else {
let notification = UILocalNotification()
... <setting up an iOS8/9 notification>
Timer.scheduledTimer(timeInterval: 20.0,
target: self,
selector: #selector(self.cancelDeliveredNotification),
userInfo: notification as Any?,
repeats: false)
die Cancelling-Funktion:
func cancelDeliveredNotification(_ sender: Timer) {
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: ["myidentifier"])
} else {
if let notificationToCancel = sender.userInfo as? UILocalNotification {
UIApplication.shared.cancelLocalNotification(notificationToCancel)
}
}
alternativ können Sie auch UNUserNotificationCenter.current().removeAllDeliveredNotifications()
tun
keine News und Ideen zu diesem Thema, ich schwöre, ich Habe die Facebook App gesehen das ich aber nichts online finde? –