简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM