Zamknięcie powiadomienia w 20 sekund:
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)
funkcja redukcji:
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)
}
}
alternatywnie można też zrobić UNUserNotificationCenter.current().removeAllDeliveredNotifications()
Wszelkie informacje lub pomysły w tej sprawie, przysięgam I Widziałeś, że aplikacja na Facebooku to robi, ale nie mogę znaleźć niczego online? –