我正在寻找很长时间,没有答案解决了我的问题 我正在关注推送通知的Firebase教程并实现了AppDelegate代码。
但Xcode不承认'FIRMessagingDelegate','Messaging'和'FIRMessagingRemoteMessage'。
我曾尝试过更新仓库,重新创建等等。
以下是代码:
import UIKit
import CoreData
import Firebase
import UserNotifications
import FirebaseMessaging
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//FirebaseApp.configure() - Documentação
FIRApp.configure()
if #available(iOS 10.0, *) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
return true
}
//More code..
}
// [START ios_10_message_handling]
@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 full message.
print(userInfo)
// Change this to your preferred presentation option
completionHandler([])
}
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
// Print full message.
print(userInfo)
completionHandler()
}
}
extension AppDelegate : FIRMessagingDelegate {
// [START refresh_token]
func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
print("Firebase registration token: \(fcmToken)")
}
// [END refresh_token]
// [START ios_10_data_message]
// Receive data messages on iOS 10+ directly from FCM (bypassing APNs) when the app is in the foreground.
// To enable direct data messages, you can set Messaging.messaging().shouldEstablishDirectChannel to true.
func messaging(_ messaging: Messaging, didReceive remoteMessage: FIRMessagingRemoteMessage) {
print("Received data message: \(remoteMessage.appData)")
}
// [END ios_10_data_message]
} //*/
答案 0 :(得分:3)
您使用的是什么版本的Firebase?根据{{3}},Swift中Firebase 4.0.0的类名更改。所以FIRMessagingDelegate
现在是MessagingDelegate
,依此类推。请参阅迁移指南documentation
答案 1 :(得分:1)
检查您是否具有最新版本的firebase推送通知库。
他们的一些旧东西已被弃用和删除。
如果您的项目中已安装了这些Pod,也请检查Project Navigator/Pods.xcodeproj/Targets
,如果未将它们添加到Podfile
答案 2 :(得分:0)
FIRMessagingRemoteMessage
已更新为MessagingRemoteMessage