[SOLVED] Firebase APNS Token not set Flutter iOS
If you're facing issue with Firebase initialization in Flutter in spite of doing everything right.
You may be missing setting the APNS token in app delegate file in xCode. You may use the following code which sets it for you and fixes Firebase init error.
import UIKit
import Flutter
import Firebase
import FirebaseMessaging
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
print("fb tokennnnnn: ")
FirebaseApp.configure()
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
print("X__APNS: \(String(describing: deviceToken))")
print("apns tokennnnnn: ")
print(deviceToken)
let firebaseAuth = Auth.auth()
firebaseAuth.setAPNSToken(deviceToken, type: AuthAPNSTokenType.unknown)
super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}
}