我总是在使用本教程部署firebase时编译错误: https://firebase.google.com/docs/cloud-messaging/ios/client 我的部署SDK是9.0。
我该如何解决这个问题?
无法指定类型的值' AppDelegate'输入' UNUserNotificationCenterDelegate?'
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
}
答案 0 :(得分:19)
在AppDelegate结束时,您需要添加2个扩展名(UNUserNotificationCenterDelegate,MessagingDelegate)
请参阅此示例应用的源代码: https://github.com/firebase/quickstart-ios/tree/master/messaging