SULUserNotificationCenter 0.1.7

SULUserNotificationCenter 0.1.7

测试已测试
Lang语言 SwiftSwift
许可 MIT
发布最新发布2017年5月
SwiftSwift 版本3.0
SPM支持 SPM

Sunus Lee 维护。



  • sunuslee

SULUserNotificationCenter

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