1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-08 04:20:07 +02:00

♻️ Require at least macOS 11, various refactors

This commit is contained in:
2021-12-05 02:54:03 +01:00
parent 924edf6f96
commit 46867ad25e
8 changed files with 55 additions and 27 deletions

View File

@ -6,14 +6,42 @@
//
import Foundation
import UserNotifications
class LocalNotification {
public static func askForPermission() {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert], completionHandler: { granted, error in
if granted {
print("PHP Monitor has permission to show notifications.")
} else {
print("PHP Monitor does not have permission to show notifications.")
}
if let error = error {
print("PHP Monitor encounted an error determining notification permissions:")
print(error)
}
})
}
public static func send(title: String, subtitle: String) {
let notification = NSUserNotification()
notification.title = title
notification.subtitle = subtitle
NSUserNotificationCenter.default.deliver(notification)
let content = UNMutableNotificationContent()
content.title = title
content.body = subtitle
let uuidString = UUID().uuidString
let request = UNNotificationRequest(
identifier: uuidString,
content: content,
trigger: nil
)
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.add(request) { (error) in
if error != nil {
print(error!)
}
}
}
}