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:
@ -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!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user