使用此教程部署Firebase时,我总是会编译错误:
https://firebase.google.com/docs/cloud-messaging/ios/client
我的部署SDK是9.0。
我遇到的错误:
我怎样才能解决这个问题?
第一种情况-我逐步进行的工作(遵循本教程):
pod“Firebase/Core”
pod“Firebase/Messaging”
第二种情况-通过github存储库(https://github.com/firebase/quickstart-ios下的“messaging”文件夹)下载了Google演示iOS客户端应用程序
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)
请参阅此示例应用程序的源代码:
https://github.com/firebase/quickstart-ios/tree/master/messaging
关于ios - Firebase-无法将 'AppDelegate'类型的值分配给 'UNUserNotificationCenterDelegate?'类型,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40746232/