import UIKit import UserNotifications @main class AppDelegate: UIResponder, UIApplicationDelegate { func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { // Request permission UNUserNotificationCenter.current().delegate = self requestNotificationPermission(application: application) setupNotificationActions() return true } func requestNotificationPermission(application: UIApplication) { let center = UNUserNotificationCenter.current() center.requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in if granted { DispatchQueue.main.async { application.registerForRemoteNotifications() } } } } // Successfully registered func application( _ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data ) { let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined() print("✅ Device Token:", token) } // Failed to register func application( _ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error ) { print("❌ Failed:", error) } func setupNotificationActions() { // Action 1 let acceptAction = UNNotificationAction( identifier: "ACCEPT_ACTION", title: "Accept", options: [.foreground] ) // Action 2 let rejectAction = UNNotificationAction( identifier: "REJECT_ACTION", title: "Reject", options: [.destructive] ) // Category let category = UNNotificationCategory( identifier: "INVITE_CATEGORY", actions: [acceptAction, rejectAction], intentIdentifiers: [], options: [] ) UNUserNotificationCenter.current().setNotificationCategories([category]) } } extension AppDelegate: UNUserNotificationCenterDelegate { // Foreground notification func userNotificationCenter( _ center: UNUserNotificationCenter,willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void ) { completionHandler([.banner, .sound]) } // Tap on notification func userNotificationCenter(_ center: UNUserNotificationCenter,didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { switch response.actionIdentifier { case "ACCEPT_ACTION": APIService.sendAction( action: "accept", notificationId: "101" ) // API call / navigation / update UI case "REJECT_ACTION": APIService.sendAction( action: "reject", notificationId: "102" ) case UNNotificationDefaultActionIdentifier: print("📲 Notification tapped") default: break } completionHandler() } }