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

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

概述我总是在使用本教程部署firebase时编译错误: https://firebase.google.com/docs/cloud-messaging/ios/client 我的部署SDK是9.0. 我得到的错误: 我怎样才能解决这个问题? Cannot assign value of type ‘AppDelegate’ to type ‘UNUserNotificationCenterDeleg 我总是在使用本教程部署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)

请参阅此示例应用的源代码:
@L_301_2@

总结

以上是内存溢出为你收集整理的ios – Firebase – 无法指定’AppDelegate’类型的值来键入’UNUserNotificationCenterDelegate?’全部内容,希望文章能够帮你解决ios – Firebase – 无法指定’AppDelegate’类型的值来键入’UNUserNotificationCenterDelegate?’所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1101894.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存