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

前端之家收集整理的这篇文章主要介绍了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中的代码

@H_404_30@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

猜你在找的iOS相关文章