横幅、警报和徽章都是NSUserNotification
实例类型。聊天回复图像是alert
样式的一个示例。
要更改应用程序的用户NSUserNotification
显示样式,请在应用程序文件中设置NSUserNotificationAlertStyle
to的值。我应该注意到 Cocoa SDK 中存在已知问题和开放雷达。默认值为. _alert
Info.plist
banner
然后,您可以使用显示信息和显示的通知按钮来自定义警报。
有关如何自定义警报上的按钮、占位符文本等的信息,请参阅NSUserNotification
API 参考。
我是这样做的(Swift 2.2,如果您使用的是 Swift 2.3 或 3,您的语法可能会有所不同)。关键是设置hasReplyButton
为true
。
let notification = NSUserNotification()
notification.hasActionButton = true
notification.actionButtonTitle = "Agree"
notification.title = "Title"
notification.informativeText = "Text."
notification.responsePlaceholder = "Placeholder"
notification.hasReplyButton = true
NSUserNotificationCenter.defaultUserNotificationCenter().deliverNotification(notification)

