在FIRMessagingDelegate类的扩展中,抛出错误:
使用未声明类型'FIRMessagingDelegate'
此外,didFinishLaunchinWithOptions
方法中会抛出此错误:
'FIRMessaging'类型的值没有成员'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 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)
}
}
答案 0 :(得分:4)
请尝试运行pod update
,这对这些人来说是一个有效的解决方案 - > https://github.com/firebase/quickstart-ios/issues/107
答案 1 :(得分:0)
使用
MessagingDelegateUser
代替
FIRMessagingDelegate
FIRMessagingDelegate updated to MessagingDelegateUser