微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ios – Firebase – 无法指定’AppDelegate’类型的值来键入’UNUserNotificationCenterDelegate?’

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

我得到的错误

我怎样才能解决这个问题?

Cannot assign value of type ‘AppDelegate’ to type ‘UNUserNotificationCenterDelegate?’

一个场景 – 我一步一步地做了什么(按照教程):

> pod init具有以下内容
pod’Firebase / Core’
pod’Firebase / Messaging’
> pod安装
>在AppDelegate类之上“导入Firebase”

第二个场景 – 通过github存储库下载谷歌演示iOS客户端应用程序(https://github.com/firebase/quickstart-ios下的“messaging”文件夹)

>编译他们的应用程序……工作正常.
>根据以下步骤,将我们现有的XCode项目的逻辑编译为:
> pod init包含以下内容:pod’Firebase / Messaging’
> pod安装
>导入以下内容:UIKit,UserNotifications,Firebase,FirebaseInstanceID,FirebaseMessaging

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,.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,FIRMessagingDelegate)

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

原文地址:https://www.jb51.cc/iOS/332672.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐