title: Firebase FCM Push Notifications not working on iOS Swift
body: <p>I have developed an iOS app, in swift Xcode 11.5, and it is working fine. But when I tried to configure Firebase Cloud Messaging push Notifications, it didn't work!</p>
  <p>I've followed the instruction on Firebase console to connect the App, and it was the Firebase account is linked correctly. and this is my AppDelegate.swift:</p>
  <pre><code>import UIKit
  import Firebase
  import FirebaseInstanceID
  import FirebaseMessaging
  import UserNotifications
  
  @UIApplicationMain
  class AppDelegate: UIResponder, UIApplicationDelegate, QBRTCClientDelegate {
  
      let gcmMessageIDKey = &quot;gcmMessageIDKey&quot;
      
      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -&gt; Bool {
          
          FirebaseApp.configure()
          if #available(iOS 10.0, *) {
            // For iOS 10 display notification (sent via APNS)
            UNUserNotificationCenter.current().delegate = self
  
            let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
            UNUserNotificationCenter.current().requestAuthorization(
              options: authOptions,
              completionHandler: {_, _ in })
          } else {
            let settings: UIUserNotificationSettings =
            UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
            application.registerUserNotificationSettings(settings)
          }
  
          application.registerForRemoteNotifications()
          Messaging.messaging().delegate = self
          
          return true
      }
      
      func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
        // If you are receiving a notification message while your app is in the background,
        // this callback will not be fired till the user taps on the notification launching the application.
        // TODO: Handle data of notification
  
        // With swizzling disabled you must let Messaging know about the message, for Analytics
        // Messaging.messaging().appDidReceiveMessage(userInfo)
  
        // Print message ID.
        if let messageID = userInfo[gcmMessageIDKey] {
          print(&quot;Message ID: \(messageID)&quot;)
        }
  
        // Print full message.
        print(userInfo)
      }
  
      func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
                       fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -&gt; Void) {
        // If you are receiving a notification message while your app is in the background,
        // this callback will not be fired till the user taps on the notification launching the application.
        // TODO: Handle data of notification
  
        // With swizzling disabled you must let Messaging know about the message, for Analytics
        // Messaging.messaging().appDidReceiveMessage(userInfo)
  
        // Print message ID.
        if let messageID = userInfo[gcmMessageIDKey] {
          print(&quot;Message ID: \(messageID)&quot;)
        }
  
        // Print full message.
        print(userInfo)
  
        completionHandler(UIBackgroundFetchResult.newData)
      }
  
  }
  
  @available(iOS 10, *)
  extension AppDelegate : UNUserNotificationCenterDelegate {
  
    // Receive displayed notifications for iOS 10 devices.
    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                willPresent notification: UNNotification,
      withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -&gt; Void) {
      let userInfo = notification.request.content.userInfo
  
      // With swizzling disabled you must let Messaging know about the message, for Analytics
      // Messaging.messaging().appDidReceiveMessage(userInfo)
  
      // Print message ID.
      if let messageID = userInfo[gcmMessageIDKey] {
        print(&quot;Message ID: \(messageID)&quot;)
      }
  
      // Print full message.
      print(userInfo)
  
      // Change this to your preferred presentation option
      completionHandler([[.alert, .sound]])
    }
  
    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                didReceive response: UNNotificationResponse,
                                withCompletionHandler completionHandler: @escaping () -&gt; Void) {
      let userInfo = response.notification.request.content.userInfo
      // Print message ID.
      if let messageID = userInfo[gcmMessageIDKey] {
        print(&quot;Message ID: \(messageID)&quot;)
      }
  
      // Print full message.
      print(userInfo)
  
      completionHandler()
    }
  }
  
  extension AppDelegate: MessagingDelegate {
      func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
          InstanceID.instanceID().instanceID { (result, error) in
            if let error = error {
              print(&quot;Error fetching remote instance ID: \(error)&quot;)
            } else if let result = result {
              print(&quot;Remote instance ID token: \(result.token)&quot;)
            }
          }
          print(&quot;Firebase registration token: \(fcmToken)&quot;)
  
          let dataDict:[String: String] = [&quot;token&quot;: fcmToken]
          NotificationCenter.default.post(name: Notification.Name(&quot;FCMToken&quot;), object: nil, userInfo: dataDict)
          // TODO: If necessary send token to application server.
          // Note: This callback is fired at each app startup and whenever a new token is generated.
          Messaging.messaging().isAutoInitEnabled = true
      }
  }
  </code></pre>
  <p>I installed the Firebase/Core, Firebase/Analytics and Firebase/Messaging pods to the project.
  I added FirebaseAppDelegateProxyEnabled to the Info.plist and set it to NO.</p>
  <p>I've also set up the Production APNS form Apple developer account, and i think it is set correctly.</p>
  <p>I've tested sending the Push Notifications locally from the terminal, and it is working.</p>
  <p>But the problem is that the notifications are not being received when i do a test notification from Firebase console.</p>
  <p>Please advise on how to solve this problem.</p>