import Flutter import UIKit import Firebase import FirebaseMessaging @main @objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { // مقداردهی Firebase FirebaseApp.configure() // ثبت Plugin های Flutter GeneratedPluginRegistrant.register(with: self) // تنظیمات Notification Center UNUserNotificationCenter.current().delegate = self Messaging.messaging().delegate = self // درخواست مجوز نوتیفیکیشن UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in if let error = error { print("Error requesting notification permissions: \(error)") } print("Permission granted: \(granted)") } // ثبت دستگاه برای دریافت Remote Notifications application.registerForRemoteNotifications() return super.application(application, didFinishLaunchingWithOptions: launchOptions) } // متد دریافت APNs Token و ارسال آن به Firebase override func application( _ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data ) { Messaging.messaging().apnsToken = deviceToken } } // افزودن پروتکل‌های UNUserNotificationCenterDelegate و MessagingDelegate extension AppDelegate: UNUserNotificationCenterDelegate, MessagingDelegate { // مدیریت دریافت توکن Firebase func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) { print("Firebase FCM Token: \(fcmToken ?? "No Token")") // اگر نیاز به ارسال توکن به سرور دارید، اینجا انجام دهید. } // مدیریت پیام‌های دریافت‌شده هنگام باز بودن اپلیکیشن func userNotificationCenter( _ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void ) { let userInfo = notification.request.content.userInfo print("Foreground Notification Received: \(userInfo)") completionHandler([.banner, .sound, .badge]) } }