Skip to content

Instantly share code, notes, and snippets.

@ericdke
Created October 10, 2014 21:01
Show Gist options
  • Star 27 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save ericdke/fec20e6db9e0aa25e8ea to your computer and use it in GitHub Desktop.
Save ericdke/fec20e6db9e0aa25e8ea to your computer and use it in GitHub Desktop.
Deliver an OSX notification with Swift
func showNotification() -> Void {
var notification = NSUserNotification()
notification.title = "Test from Swift"
notification.informativeText = "The body of this Swift notification"
notification.soundName = NSUserNotificationDefaultSoundName
NSUserNotificationCenter.defaultUserNotificationCenter().deliverNotification(notification)
}
//showNotification()
@fhefh2015
Copy link

https://gist.github.com/code4you2021/cf184702b298181238aeb3fd781db203

UNUserNotificationCenter | Apple Developer Documentation
https://developer.apple.com/documentation/usernotifications/unusernotificationcenter

Availability
iOS 10.0+
iPadOS 10.0+
macOS 10.14+
Mac Catalyst 13.0+
tvOS 10.0+
watchOS 3.0+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment