"Error : Use of undeclared type MessagingDelegate" in Firebase messaging
Solution 1
add import FirebaseMessaging
at the top of the page would resolve the issue
Solution 2
it is about the version of firebase ,in this case change MessagingDelegate
to FIRMessagingDelegate
and the function [START refresh_token] from
func messaging(_ messaging: Messaging, didReceiveRegistrationToken
fcmToken: String) {
print("Firebase registration token: \(fcmToken)")
}
to
func messaging(_ messaging: FIRMessaging, didReceiveRegistrationToken
fcmToken: String) {
print("Firebase registration token: \(fcmToken)")
}
and last
func messaging(_ messaging: Messaging, didReceive remoteMessage:
MessagingRemoteMessage) {
print("Received data message: \(remoteMessage.appData)")
}
to
func applicationReceivedRemoteMessage(_ remoteMessage:
FIRMessagingRemoteMessage) {
print("Received data message: \(remoteMessage.appData)")
}
complete answer is
extension AppDelegate : FIRMessagingDelegate {
func applicationReceivedRemoteMessage(_ remoteMessage: FIRMessagingRemoteMessage) {
print("Received data message: \(remoteMessage.appData)")
}
// [START refresh_token]
func messaging(_ messaging: FIRMessaging, didReceiveRegistrationToken fcmToken: String) {
print("Firebase registration token: \(fcmToken)")
}}
Solution 3
For Swift 4 to up:
What version of Firebase are you using? According to the documentation, class names changes for Firebase 4.0.0 in Swift. So FIRMessagingDelegate, is now MessagingDelegate, and so on. See the migration guide here
Solution 4
MessagingDelegate
is undeclared type, says the error. Make sure you're importing the Firebase Framework, like so:
import Firebase
If importing the Firbease framework gives you an error no such module Firebase
, then you need to fix that first, that no such module Firebase
error. How to fix that? You need to check the version of your Firebase pod against the version of your Swift language. Perhaps the Firebase version you have uses the Swift 4.0 while your project uses Swift 3.0.
To make sure you're installing the pod dedicated for Swift 3.0, add can add a checker for build settings of each pod to your Podfile. Also make sure you're installing Messaging
framework of Firebase, like so:
pod 'Firebase/Auth'
pod 'Firebase/Core'
pod 'Firebase/Database'
pod 'Firebase/Messaging'
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0'
end
end
end
Solution 5
Update the podfile using pod update
and if pod update is failed to update, delete the podfile.lock and run pod install
Related videos on Youtube
Heckyl Technologies
Updated on June 04, 2022Comments
-
Heckyl Technologies almost 2 years
I have updated my firebase messaging pod recently and followed the Quickstart guide of Firebase to perform necessary changes of upgradation.
I added the new
extension AppDelegate : MessagingDelegate
extension but getting certain errors. -
Heckyl Technologies over 6 yearsimport Firebase itself giving me error 'no such module Firebase' error ; which is why I added import FirebaseCore and import FirebaseInstanceID
-
Heckyl Technologies over 6 yearsit isn't working; I downgraded the version of Firebase to 4.0.0 which supports Swift3 but it didn't work. Still getting the same error
-
Glenn Posadas over 6 yearsHave you done the ritual? Cmd+Shift+K and Cmd+Shift+AltOption+K? :)
-
Heckyl Technologies over 6 yearsYes Already did that multiple times. It's just that I have added pod 'Firebase', '~> 4.0.0' in podfile but while installation it showed in terminal as "Installing Firebase 4.0.4 (was 4.3.0)". do you feel it has any impact to this
-
Glenn Posadas over 6 yearsI think so. Can you check out my edited answer, I've added some checker for you.
-
Heckyl Technologies over 6 yearsSo basically, MessagingDelegate belongs to FirebaseMessaging. I tired adding import FirebaseMessaging instead of import Firebase and it worked. Now tell me one thing, the notification from console sending for single device; does work without APNs certificate or not?
-
Glenn Posadas over 6 yearsYou always need APNs certificate for remote push notifications :) If my answer helped you out, you might want to select this as the
answer
.