I used the following class to post local notifications:
class LocalNotification: NSObject, UNUserNotificationCenterDelegate{
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification) async -> UNNotificationPresentationOptions{
print("torna notification")
return [.sound, .badge, .banner]
}
func localNotification(_ title:String, message:String, sound:UNNotificationSound?, badge:Int?, interval:TimeInterval, userInfo: [AnyHashable : Any]?, category:UNNotificationCategory?=nil){
let content = UNMutableNotificationContent()
content.title = NSString.localizedUserNotificationString(forKey: title, arguments: nil)
content.body = NSString.localizedUserNotificationString(forKey: message, arguments: nil)
content.sound=sound
let ti = interval * 60
let seconds = ti.second
let minutes = ti.minute
let hours = ti.hour
//let ms = Int((interval.truncatingRemainder(dividingBy: 1)) * 1000)
var dateInfo = DateComponents()
dateInfo.hour=hours
dateInfo.minute=minutes
dateInfo.second=seconds
let trigger = UNCalendarNotificationTrigger(dateMatching: dateInfo, repeats: false)
let request = UNNotificationRequest(identifier: message, content: content, trigger: trigger)
let center = UNUserNotificationCenter.current()
center.delegate = self
center.add(request) { (error : Error?) in
if let theError = error {
print(theError.localizedDescription)
}
}
}
}
But still function:
UNUserNotificationCenterDelegate{
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification) async
is never called and more importantly no notification is delivered, either sound or banner.