I would like to keep notifying users of the end of their meditation with a local notification on Swift 6.
So I used code:
struct LocalNotification{
**static** **let** shared: LocalNotification = { **let** instance = LocalNotification() // setup code Task.**init**{ **do** { **let** center = UNUserNotificationCenter.current() **let** authorized=**try** **await** center.requestAuthorization(options: \[.alert, .badge, .sound\]) **if** authorized{ **await** UIApplication.shared.registerForRemoteNotifications() } } **catch** { print(error.localizedDescription) } } **return** instance }() **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**) **async**{ **let** content = UNMutableNotificationContent() content.title = NSString.localizedUserNotificationString(forKey: title, arguments: **nil**) content.body = NSString.localizedUserNotificationString(forKey: message, arguments: **nil**) content.subtitle = "iPuja" print("title \\(content.title)") print("body \\(content.body)") content.sound=UNNotificationSound.defaultRingtone 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** uuidString = UUID().uuidString **let** trigger = UNCalendarNotificationTrigger(dateMatching: dateInfo, repeats: **false**) **let** request = UNNotificationRequest(identifier: uuidString, content: content, trigger: trigger) //let notificationCenter = UNUserNotificationCenter.current() //notificationCenter.delegate = self **do** { **let** notificationCenter = UNUserNotificationCenter.current() **try** **await** notificationCenter.add(request) } **catch** { print(error.localizedDescription) // Handle errors that may occur during add. } }}
that at the moment just produces a sound, even if in a strange way: I had to assign to content.sound UNNotificationSound.defaultRingtone to have my alert sound being played. Still there is no producing the alert. I'm using Xcode 26.6 and iOS 27.0 beta 3.