I have a simple local notification that only plays a sound

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.

This forum is primarily about Swift, the language. For questions specific to Apple frameworks, I would advise posting them on the Apple Developer Forums.

P.S. When posting code snippets, wrap your code with three backticks and add the swift keyword after the opening backticks:

```swift
// code here
```
1 Like

That was swift code. I do not understand otherwise what your mean by a swift forum.

Still I understood what you mean, albeit I had no meaningful responses on the Apple Forums, so I tried otherwhere.

Swift the language as in working ON Swift. The forums is mainly used by the compiler team, maintainers, contributors and the Evolution process.