Ryan Ryan - 1 month ago 29
Swift Question

Use of undeclared type 'FIRMessagingDelegate'

I am very new to Apple Push Notifications and I am getting errors in the documentation code and in the code provided in some other StackOverflow posts. In an extension to the FIRMessagingDelegate class, an error is thrown:

Use of undeclared type 'FIRMessagingDelegate'
. Additionally, this error is thrown in the
didFinishLaunchinWithOptions
method:
Value of type 'FIRMessaging' has no member 'remoteMessageDelegate'


import UIKit
import Firebase
import UserNotifications
import FirebaseMessaging
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

override init() {
FIRApp.configure() //this is the updated version.

}


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//FIRApp.configure()

if #available(iOS 10.0, *) {
let authOptions : UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_,_ in })

// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
// For iOS 10 data message (sent via FCM)
FIRMessaging.messaging().remoteMessageDelegate = self

}

application.registerForRemoteNotifications() // ERROR: Value of type 'FIRMessaging' has no member 'remoteMessageDelegate'

return true
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quit4rRs the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification

// Print message ID.
print("Message ID: \(userInfo["gcm.message_id"]!)")

// Print full message.
print(userInfo)
}

func tokenRefreshNotification() {
let fcmDeviceToken = FIRInstanceID.instanceID().token()
// TODO: Send token to server
}

}


@available(iOS 10, *)
extension AppDelegate : UNUserNotificationCenterDelegate {

// Receive displayed notifications for iOS 10 devices.

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
// Print message ID.
print("Message ID: \(userInfo["gcm.message_id"]!)")

// Print full message.
print("%@", userInfo)

}

}

extension AppDelegate : FIRMessagingDelegate { // ERROR: Use of undeclared type 'FIRMessagingDelegate'
// Receive data message on iOS 10 devices.
func applicationReceivedRemoteMessage(_ remoteMessage: FIRMessagingRemoteMessage) { // ERROR: Use of undeclared type 'FIRMessagingRemoteMessage'
print("%@", remoteMessage.appData)
}
}

Answer

Please try running pod update , this has been a working solution for these people -> https://github.com/firebase/quickstart-ios/issues/107

Comments