18

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 } 
6
  • 3
    did your AppDelegate class implements "UNUserNotificationCenterDelegate" protocol? If not, the compiler cant match the type and that is why gives the error. Commented Nov 22, 2016 at 15:54
  • The weird thing is that google's ios client example only implements UIResponder, UIApplicationDelegate... I've added UNUserNotificationCenterDelegate and FIRMessagingDelegate. Now, it says "AppDelegate" doesn't confirm with "FIRMessagingDelegate". I'm gonna research on this. Thanks. Commented Nov 22, 2016 at 16:10
  • 1
    Got it... The example has 2 extensions... lol But the tutorial doesn't have anything related to this. Anyways. Commented Nov 22, 2016 at 16:14
  • @user3427013 how did you solve the "Now, it says "AppDelegate" doesn't confirm with "FIRMessagingDelegate"? I'm getting that error too. Commented Dec 12, 2016 at 5:48
  • @JozemiteApps see answer below. Commented Feb 6, 2017 at 10:32

1 Answer 1

31

At the end of AppDelegate you need to add 2 extensions (UNUserNotificationCenterDelegate, MessagingDelegate)

See the source code from this sample app: https://github.com/firebase/quickstart-ios/tree/master/messaging

Sign up to request clarification or add additional context in comments.

1 Comment

FIRMessagingDelegate has been renamed to MessagingDelegate

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.