I always get compiling erros when deploying firebase using this tutorial: https://firebase.google.com/docs/cloud-messaging/ios/client My deployment SDK is 9.0.
Errors I get:
How can I fix this?
Cannot assign value of type 'AppDelegate' to type 'UNUserNotificationCenterDelegate?'
1st scenario - What I did step by step (following the tutorial):
- pod init with the following: pod 'Firebase/Core' pod 'Firebase/Messaging'
- pod install
- "import Firebase" on top of AppDelegate class
2nd scenario - Downloaded google demo iOS client app through a github repository ("messaging" folder under https://github.com/firebase/quickstart-ios)
- compiled their app... worked fine.
- compied to my existing XCode project their logic as according to the following steps:
- pod init with the following: pod 'Firebase/Messaging'
- pod install
- imported the following: UIKit, UserNotifications, Firebase, FirebaseInstanceID, FirebaseMessaging
Code in 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 }