本文介绍了Firebase-无法将类型"AppDelegate"的值分配给类型"UNUserNotificationCenterDelegate?"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用此教程部署Firebase时,我总是会编译错误: https://firebase.google.com/docs/cloud-messaging/ios/client我的部署SDK是9.0.

I always get compiling erros when deploying firebase using this tutorial:https://firebase.google.com/docs/cloud-messaging/ios/clientMy deployment SDK is 9.0.

我该如何解决?

第一种情况-我逐步进行的操作(按照本教程操作):

  • pod初始化,其中包含以下内容:pod"Firebase/Core"pod"Firebase/Messaging"
  • pod安装
  • 导入Firebase";在AppDelegate类的顶部
    • 编译了他们的应用程序……工作正常.
    • 按照以下步骤将其逻辑与我现有的XCode项目进行比较:
    • 包含以下内容的Pod初始化:"Firebase/Messaging"窗格
    • pod安装
    • 导入了以下内容:UIKit,用户通知,Firebase,FirebaseInstanceID,FirebaseMessaging

    AppDelegate中的代码:

    Code in AppDelegate:

    func application(_ application: UIApplication,
                         didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
            // [START register_for_notifications]
            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
            } else {
                let settings: UIUserNotificationSettings =
                    UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
                application.registerUserNotificationSettings(settings)
            }
            application.registerForRemoteNotifications()
            // [END register_for_notifications]
            FIRApp.configure()
            // Add observer for InstanceID token refresh callback.
            NotificationCenter.default.addObserver(self,
                                                   selector: #selector(self.tokenRefreshNotification),
                                                   name: .firInstanceIDTokenRefresh,
                                                   object: nil)
            return true
        }
    
    
    
    

    推荐答案

    在AppDelegate的末尾,您需要添加2个扩展(UNUserNotificationCenterDelegate,MessagingDelegate)

    At the end of AppDelegate you need to add 2 extensions (UNUserNotificationCenterDelegate, MessagingDelegate)

    请参阅此示例应用程序的源代码: https://github.com/firebase/quickstart-ios/tree/master/messaging

    See the source code from this sample app:https://github.com/firebase/quickstart-ios/tree/master/messaging

    这篇关于Firebase-无法将类型"AppDelegate"的值分配给类型"UNUserNotificationCenterDelegate?"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 05:52