Swift:Cocoa,mac OS Catalina 中未显示本地通知

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

Mac OS Catalina 上不显示你好通知,这是我的代码:

    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)
    }

我注意到在我的 mac 应用程序中,现在当我打开应用程序时会出现一个通知请求。也许我必须实施它?但我找不到任何关于它的文档。如何查看本地通知...

即使使用 UserNotification 也不起作用

根据 https://developer.apple.com/documentation/foundation/nsusernotification

NSUserNotification 已在 MacOS 10.14 之后弃用

相反,您可能想看看 UserNotification 框架,如 https://developer.apple.com/documentation/usernotifications?language=objc

此外,请求用户许可以授权通知现在至关重要。