Implement send notification
This commit is contained in:
@@ -4,17 +4,48 @@ import Libbox
|
||||
import Library
|
||||
import Network
|
||||
import UIKit
|
||||
import UserNotifications
|
||||
|
||||
class ApplicationDelegate: NSObject, UIApplicationDelegate {
|
||||
class ApplicationDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate {
|
||||
private var profileServer: ProfileServer?
|
||||
|
||||
func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
|
||||
NSLog("Here I stand")
|
||||
LibboxSetup(FilePath.sharedDirectory.relativePath, FilePath.workingDirectory.relativePath, FilePath.cacheDirectory.relativePath, false)
|
||||
let notificationCenter = UNUserNotificationCenter.current()
|
||||
notificationCenter.setNotificationCategories([
|
||||
UNNotificationCategory(
|
||||
identifier: "OPEN_URL",
|
||||
actions: [
|
||||
UNNotificationAction(identifier: "COPY_URL", title: "Copy URL", options: .foreground, icon: UNNotificationActionIcon(systemImageName: "clipboard.fill")),
|
||||
UNNotificationAction(identifier: "OPEN_URL", title: "Open", options: .foreground, icon: UNNotificationActionIcon(systemImageName: "safari.fill")),
|
||||
],
|
||||
intentIdentifiers: []
|
||||
),
|
||||
]
|
||||
)
|
||||
notificationCenter.delegate = self
|
||||
setup()
|
||||
return true
|
||||
}
|
||||
|
||||
func userNotificationCenter(_: UNUserNotificationCenter, willPresent _: UNNotification) async -> UNNotificationPresentationOptions {
|
||||
.banner
|
||||
}
|
||||
|
||||
func userNotificationCenter(_: UNUserNotificationCenter, didReceive response: UNNotificationResponse) async {
|
||||
if let url = response.notification.request.content.userInfo["OPEN_URL"] as? String {
|
||||
switch response.actionIdentifier {
|
||||
case "COPY_URL":
|
||||
UIPasteboard.general.string = url
|
||||
case "OPEN_URL":
|
||||
fallthrough
|
||||
default:
|
||||
await UIApplication.shared.open(URL(string: url)!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func setup() {
|
||||
do {
|
||||
try UIProfileUpdateTask.configure()
|
||||
|
||||
Reference in New Issue
Block a user