i am trying to run my code and keep telling me
error: no such module 'FirebaseInstanceID'
import FirebaseInstanceID
my code in AppDelegate.swift
import UIKit
import Flutter
import Firebase
import FirebaseAuth
import UserNotifications
import FirebaseInstanceID
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let firebaseAuth = Auth.auth()
firebaseAuth.setAPNSToken(deviceToken, type: AuthAPNSTokenType.unknown)
}
override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
let firebaseAuth = Auth.auth()
if (firebaseAuth.canHandleNotification(userInfo)){
print(userInfo)
return
}
}
}
i think is missing in my pod, i did not no how to install it to my pod file.
The problem is that FirebaseInstanceID has recently became deprecated, so the above code is no longer working with the new version. FCM token is now provided directly on the Messaging instance. Modify the code above in your AppDelegate.swift to match the one below.
Firebase Instance ID provides a unique identifier for each app instance and a mechanism to authenticate and authorize actions (example: sending FCM messages). Instance ID is stable except when: App deletes Instance ID. App is restored on a new device. User uninstalls/reinstall the app. User clears app data.
If you have implemented Firebase Cloud Messaging for notifications, you had to add FirebaseInstanceID package in order to receive a FCM token. You also had to add the following code to your AppDelegate.swift file: The problem is that FirebaseInstanceID has recently became deprecated, so the above code is no longer working with the new version.
Instance ID is stable except when: Once an Instance ID is generated, the library periodically sends information about the application and the device where it's running to the Firebase backend. To stop this, see deleteInstanceId ().
FirebaseInstanceID is deprecated now, that is why this error is coming. Remove import FirebaseInstanceID
from your AppDelegate.swift
and instead add import FirebaseMessaging
because FCM token is now provided directly on the Messaging instance. Now replace the code of InstanceID
in didRegisterForRemoteNotificationsWithDeviceToken
with this
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
Messaging.messaging().token { (token, error) in
if let error = error {
print("Error fetching remote instance ID: \(error.localizedDescription)")
} else if let token = token {
print("Token is \(token)")
}
}
}
updated 19/07/2021
remove the FirebaseInstanceID and install Firebase Messaging latest version..
i later solve the issue by installing Firebase Messaging Plugin
Firebase messaging Plugin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With