Reputation: 2063
I have a flutter app with integrated FCM, runs ok in android but launching in iOS am getting the following error:
[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: [firebase_messaging/apns-token-not-set] APNS token has not been set yet. Please ensure the APNS token is available by calling `getAPNSToken()`.
Solutions in this question did not help, I have already created the apns token, uploaded it to firebase, see my swift code below:
import Flutter
import UIKit
import Firebase
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure();
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
}
}
And my flutter implementation:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
await FirebaseMessaging.instance.getAPNSToken();
runApp(MyApp(settings: {}));
}
I have not been able to crack this despite numerous search and AI prompts, any help here would be highly appreciated, thanks.
Upvotes: 1
Views: 58
Reputation: 2063
My mistake here was running this on iphone simulator, posting the answer so the next person does not have to go through what I went through, for FCM to work, you do not need the Swift code, just let the swift code be originally what it was unless you have your own native code, then run the app on a real device/iphone.
Upvotes: 0