从Swift脚本显示系统警报或通知

时间:2017-07-28 16:20:48

标签: swift notifications

我想显示来自Swift脚本的系统警报或通知。例如,如果Desktop文件夹中有超过30个文件,我希望看到任何类型的通知。我怎么能这样做?

1 个答案:

答案 0 :(得分:-1)

要发送本地通知,我认为你只需要使用它:

func showNotification() -> Void {
    var notification = NSUserNotification()
    notification.title = "Test from Swift"
    notification.informativeText = "The body of this Swift notification"
    notification.soundName = NSUserNotificationDefaultSoundName
    NSUserNotificationCenter.default.deliver(notification)
}

有一个detailed tutorial here