简体   繁体   English

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

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

Hello notifications are not displayed on Mac OS Catalina, here is my code:你好通知不显示在 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)
    }

I noticed that in my mac application now when I open the application a notification request appears.我注意到现在在我的 mac 应用程序中,当我打开应用程序时会出现一个通知请求。 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即使使用 UserNotification 它也不起作用

The NSUserNotification has been deprecated past MacOS 10.14 as per https://developer.apple.com/documentation/foundation/nsusernotification根据https://developer.apple.com/documentation/foundation/nsusernotification ,在 MacOS 10.14 之后, NSUserNotification已被弃用

Instead you might want to have a look at the UserNotification framework as in https://developer.apple.com/documentation/usernotifications?language=objc相反,您可能想查看https://developer.apple.com/documentation/usernotifications?language=objc中的UserNotification框架

And in addition it is now crucial to request permission from users to authorize notifications.此外,现在向用户请求授权以授权通知至关重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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