Created
September 27, 2018 10:44
-
-
Save rawnly/95de9b596c25390d3ca71e11b0d30ad6 to your computer and use it in GitHub Desktop.
Notification in swift 4.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Notification in swift 4.2 | |
// Tested on MacOS 10.14 | |
func showNotification(title: String, body: String, icon: NSImage = nil) -> Void { | |
let notification = NSUserNotification() | |
notification.title = title | |
notification.subtitle = body | |
if ( icon !== nil ) { | |
notification.contentImage = icon | |
} | |
notification.soundName = NSUserNotificationDefaultSoundName | |
NSUserNotificationCenter.default.delegate = self | |
NSUserNotificationCenter.default.deliver(notification) | |
} | |
extension ViewController: NSNotificationCenterDelegate { | |
func userNotificationCenter(_ center: NSUserNotificationCenter, shouldPresent notification: NSUserNotification) -> Bool { | |
return true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment