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.
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.
add import FirebaseMessaging
at the top of the page would resolve the issue
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)")
}}
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
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
Update the podfile using pod update
and if pod update is failed to update, delete the podfile.lock and run pod install
After updating the FirebaseMessageing to the 7.0.0 version, I've gotten the error so I had to chagne the didReceiveRegistrationToken
function in this way:
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
guard let fcmToken = fcmToken else { return }
print("Firebase registration token: \(fcmToken)")
}