测试已测试 | ✗ |
Lang语言 | SwiftSwift |
许可 | MIT |
发布最新发布 | 2017年5月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Sunus Lee 维护。
NSUserNotification 的速成替代品,包含一些实用的小调整,用 Swift 3.0 编写!通过运行 pod try SULUserNotification
查看示例
pod “SULUserNotificationCenter”
只需将您的 NSUserNotificationCenter
替换为 SULUserNotificationCenter
,如下所示
// ********REPLACE this line
// let NScenter = NSUserNotificationCenter.default
// ********With this line
let SULcenter = SULUserNotificationCenter.default
let notification = NSUserNotification.init()
notification.title = "SUL_Notification Title"
notification.subtitle = "SUL subtitle"
notification.informativeText = "SULUserNotification is a dropin replacement for NSUserNotification"
notification.actionButtonTitle = "REPLY"
notification.otherButtonTitle = "Close"
notification.contentImage = NSImage.init(named: "right-icon")
// you can custom this leftImage.
notification.leftImage = NSImage.init(named: "left-icon")
notification.deliveryDate = NSDate.init(timeIntervalSinceNow: 20) as Date
notification.hasReplyButton = true
notification.responsePlaceholder = "Response Placeholder"
notification.replyButtonTitle = "SUL_REPLY"
// ***********REPLACE this line
//NScenter.deliver(notification)
// ***********With this line
SULcenter.deliver(notification)
将 NSUserNotificationCenterDelegate
替换为 SULUserNotificationCenterDelegate
extension ViewController{
// Replace the first two delegate methods
func userNotificationCenter(_ center: NSUserNotificationCenter, shouldPresent notification: NSUserNotification) -> Bool {
return true;
}
func userNotificationCenter(_ center: NSUserNotificationCenter, didActivate notification: NSUserNotification) {
#if DEBUG
Swift.print("Function: \(type(of:self)) \(#function), line: \(#line)")
#endif
print("NSUserNotification Did Active")
}
// With this two delegate methods
func userNotificationCenter(_ center: SULUserNotificationCenter, shouldPresent notification: NSUserNotification) -> Bool {
#if DEBUG
Swift.print("Function: \(type(of:self)) \(#function), line: \(#line)")
#endif
return true
}
func userNotificationCenter(_ center: SULUserNotificationCenter, didActivate notification: NSUserNotification) {
#if DEBUG
Swift.print("Function: \(type(of:self)) \(#function), line: \(#line)")
#endif
}
}