My app produces local notification but unfortunately they only play a sound but do not produce an alert. Of course I requested authorization with:
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound]) {(granted, error) in
// Enable or disable features based on authorization.
}
And scheduled the notification with:
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 = NSInteger(interval)
let seconds = ti % 60
let minutes = (ti / 60) % 60
let hours = (ti / 3600)
//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: "EndOfMeditation", content: content, trigger: trigger)
let center = UNUserNotificationCenter.current()
center.delegate = self
center.add(request) { (error : Error?) in
if let theError = error {
print(theError.localizedDescription)
}
}
}
and have no queue about to know better.