Close Menu
  • Home
  • AI
  • Big Data
  • Cloud Computing
  • iOS Development
  • IoT
  • IT/ Cybersecurity
  • Tech
    • Nanotechnology
    • Green Technology
    • Apple
    • Software Development
    • Software Engineering

Subscribe to Updates

Get the latest technology news from Bigteetechhub about IT, Cybersecurity and Big Data.

    What's Hot

    Amazon is seeking to raise about $12B through a bond sale, its first such deal in US dollars since 2022, to help fund acquisitions, capex, and more (Bloomberg)

    November 17, 2025

    Why Puppy Yoga Is the New Wellness Fix for Busy Americans

    November 17, 2025

    How to Navigate Cloud Migration Complexity: FAQs and Best Practices

    November 17, 2025
    Facebook X (Twitter) Instagram
    Facebook X (Twitter) Instagram
    Big Tee Tech Hub
    • Home
    • AI
    • Big Data
    • Cloud Computing
    • iOS Development
    • IoT
    • IT/ Cybersecurity
    • Tech
      • Nanotechnology
      • Green Technology
      • Apple
      • Software Development
      • Software Engineering
    Big Tee Tech Hub
    Home»iOS Development»ios – How to fix “Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value” in my SMS MFA integration
    iOS Development

    ios – How to fix “Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value” in my SMS MFA integration

    big tee tech hubBy big tee tech hubOctober 31, 2025013 Mins Read
    Share Facebook Twitter Pinterest Copy Link LinkedIn Tumblr Email Telegram WhatsApp
    Follow Us
    Google News Flipboard
    ios – How to fix “Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value” in my SMS MFA integration
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link


    I have been trying to integrate MFA through firebase within my app but I am having many issues. Initially I had no crash but the sms would not send and I would get the following error If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to FIRAuth’s canHandleNotificaton: method. I then created an app delegate and I now get the following console log:

    12.3.0 – [GoogleUtilities/AppDelegateSwizzler][I-SWZ001014] App Delegate does not conform to UIApplicationDelegate protocol. ✅ Firebase configured in App init ✅ All managers initialized ✅ AppDelegate setup complete ✅ Notification permission granted ✅ Auth listener established📱 APNs token received FirebaseAuth/Auth.swift:1593: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

    The token is being received but is found to be nil.

    import SwiftUI
    import Firebase
    import FirebaseAuth
    import FirebaseCore
    import UserNotifications
    
    class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate {
        
        // ✅ Store the token until we can safely set it
        private var pendingAPNsToken: Data?
        
        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
            
            // Firebase is already configured in LocumLedgerApp.init()
            // Set up notification delegate
            UNUserNotificationCenter.current().delegate = self
            
            // Request notification authorization for MFA
            UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in
                if granted {
                    print("✅ Notification permission granted")
                    DispatchQueue.main.async {
                        application.registerForRemoteNotifications()
                    }
                } else if let error = error {
                    print("❌ Notification permission error: \(error.localizedDescription)")
                }
            }
            
            print("✅ AppDelegate setup complete")
            return true
        }
        
        // ✅ This receives the APNs token from iOS
        func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
            let tokenString = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
            print("📱 APNs token received: \(tokenString)")
            
            // Store token and attempt to set it after a delay
            self.pendingAPNsToken = deviceToken
            
            // Wait a bit longer to ensure Auth is fully initialized
            DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [weak self] in
                self?.setAPNsToken()
            }
        }
        
        // ✅ Set the APNs token once Auth is ready
        private func setAPNsToken() {
            guard let token = pendingAPNsToken else { return }
            
            Auth.auth().setAPNSToken(token, type: .unknown)
            print("✅ APNs token set in Firebase Auth")
            pendingAPNsToken = nil
        }
    
        func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
            print("❌ Failed to register for remote notifications: \(error.localizedDescription)")
        }
        
        // ✅ Handle incoming silent push (verification SMS from Firebase)
        func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping(UIBackgroundFetchResult) -> Void) {
            print("📩 Remote notification received: \(userInfo)")
            
            if Auth.auth().canHandleNotification(userInfo) {
                print("✅ Firebase Auth handled the notification (MFA verification)")
                completionHandler(.noData)
                return
            }
            
            print("ℹ️ Notification not handled by Firebase Auth")
            completionHandler(.noData)
        }
        
        // ✅ Handle notifications when app is in foreground
        func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
            print("📩 Foreground notification received")
            // For MFA silent notifications, don't show UI
            completionHandler([])
        }
    }
    
    

    I have added push notifications as well as background modes remote notifications and configured the APN keys within firebase console. How can I fix this error?



    Source link

    Error Fatal Fix implicitly Integration iOS MFA nil Optional SMS Unexpectedly unwrapping
    Follow on Google News Follow on Flipboard
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Copy Link
    tonirufai
    big tee tech hub
    • Website

    Related Posts

    Why Puppy Yoga Is the New Wellness Fix for Busy Americans

    November 17, 2025

    ios – UserDefaults doesn’t store its value

    November 16, 2025

    startup – How to fix hang after login?

    November 16, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Editors Picks

    Amazon is seeking to raise about $12B through a bond sale, its first such deal in US dollars since 2022, to help fund acquisitions, capex, and more (Bloomberg)

    November 17, 2025

    Why Puppy Yoga Is the New Wellness Fix for Busy Americans

    November 17, 2025

    How to Navigate Cloud Migration Complexity: FAQs and Best Practices

    November 17, 2025

    Fortinet Exploited, China’s AI Hacks, PhaaS Empire Falls & More

    November 17, 2025
    About Us
    About Us

    Welcome To big tee tech hub. Big tee tech hub is a Professional seo tools Platform. Here we will provide you only interesting content, which you will like very much. We’re dedicated to providing you the best of seo tools, with a focus on dependability and tools. We’re working to turn our passion for seo tools into a booming online website. We hope you enjoy our seo tools as much as we enjoy offering them to you.

    Don't Miss!

    Amazon is seeking to raise about $12B through a bond sale, its first such deal in US dollars since 2022, to help fund acquisitions, capex, and more (Bloomberg)

    November 17, 2025

    Why Puppy Yoga Is the New Wellness Fix for Busy Americans

    November 17, 2025

    Subscribe to Updates

    Get the latest technology news from Bigteetechhub about IT, Cybersecurity and Big Data.

      • About Us
      • Contact Us
      • Disclaimer
      • Privacy Policy
      • Terms and Conditions
      © 2025 bigteetechhub.All Right Reserved

      Type above and press Enter to search. Press Esc to cancel.