user8943606
user8943606

Reputation:

Swift: Cocoa, local notification not showing in mac OS Catalina

Hello notifications are not displayed on Mac OS Catalina, here is my code:

    func showNotification() {
        let notification = NSUserNotification()

        // All these values are optional
        notification.title = "Test of notification"
        notification.subtitle = "Subtitle of notifications"
        notification.informativeText = "Main informative text"
        notification.soundName = NSUserNotificationDefaultSoundName

        NSUserNotificationCenter.default.deliver(notification)
    }

I noticed that in my mac application now when I open the application a notification request appears. Maybe I have to implement that? But I can not find any documentation on it. How to view local notification...

Even with UserNotification it does not work

Upvotes: 0

Views: 1142

Answers (1)

Peter Pajchl
Peter Pajchl

Reputation: 2709

The NSUserNotification has been deprecated past MacOS 10.14 as per https://developer.apple.com/documentation/foundation/nsusernotification

Instead you might want to have a look at the UserNotification framework as in https://developer.apple.com/documentation/usernotifications?language=objc

And in addition it is now crucial to request permission from users to authorize notifications.

Upvotes: 3

Related Questions