title: Firebase Cloud Messaging not working on IOS
body: <p>So I have been trying to figure this out for a while I have followed the set up guide a few times and I can't even get the push notifications sent form the firebase console to show up. I have Phone Auth set up and working, which required push notifications and APN set up, same as FCM. Here is my AppDelegate file:</p>
  
  <pre><code>//
  //  AppDelegate.swift
  //  texter
  //
  //  Created by Johnathan Saunders on 3/28/17.
  //  Copyright © 2017 Johnathan Saunders. All rights reserved.
  //
  import UIKit
  import Firebase
  
  import UserNotifications
  @UIApplicationMain
  class AppDelegate:  UIResponder, UIApplicationDelegate,MessagingDelegate {
  
      var window: UIWindow?
      let gcmMessageIDKey = "gcm.message_id"
  
  
      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -&gt; Bool {
          // Override point for customization after application launch.
  
          FirebaseApp.configure()
  
          // [START set_messaging_delegate]
          Messaging.messaging().delegate = self
          // [END set_messaging_delegate]
          // Register for remote notifications. This shows a permission dialog on first run, to
          // show the dialog at a more appropriate time move this registration accordingly.
          // [START register_for_notifications]
          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()
          let token = Messaging.messaging().fcmToken
          print("FCM token: \(token ?? "")")
          // [END register_for_notifications]
  
          return true
      }
  
      func applicationWillResignActive(_ application: UIApplication) {
          // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
          // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
      }
  
      func applicationDidEnterBackground(_ application: UIApplication) {
          // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
          // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
      }
  
      func applicationWillEnterForeground(_ application: UIApplication) {
          // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
      }
  
      func applicationDidBecomeActive(_ application: UIApplication) {
          // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
      }
  
      func applicationWillTerminate(_ application: UIApplication) {
          // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
      }
  
      func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
          // Pass device token to auth.
          let firebaseAuth = Auth.auth()
  
          //At development time we use .sandbox
          firebaseAuth.setAPNSToken(deviceToken, type: AuthAPNSTokenType.sandbox)
          print("APNs token retrieved: \(deviceToken)")
          InstanceID.instanceID().setAPNSToken(deviceToken, type: .prod)
          // With swizzling disabled you must set the APNs token here.
          Messaging.messaging().apnsToken = deviceToken
          //At time of production it will be set to .prod
      }
  
  
      //notifcation stuff
  
      // [START receive_message]
      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("Message ID: \(messageID)")
          }
  
          // 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("Message ID: \(messageID)")
          }
  
          // Print full message.
          print(userInfo)
  
          completionHandler(UIBackgroundFetchResult.newData)
      }
      // [END receive_message]
      func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
          print("Unable to register for remote notifications: \(error.localizedDescription)")
      }
  
  
  
      // [END ios_10_message_handling]
  
  
      // [START refresh_token]
      func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
          print("Firebase registration token: \(fcmToken)")
  
          // TODO: If necessary send token to application server.
          // Note: This callback is fired at each app startup and whenever a new token is generated.
      }
      // [END refresh_token]
      // [START ios_10_data_message]
      // Receive data messages on iOS 10+ directly from FCM (bypassing APNs) when the app is in the foreground.
      // To enable direct data messages, you can set Messaging.messaging().shouldEstablishDirectChannel to true.
      func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
          print("Received data message: \(remoteMessage.appData)")
  
      }
      // [END ios_10_data_message]
  
      func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
          print("Firebase registration token: \(fcmToken)")
  
          // TODO: If necessary send token to application server.
          // Note: This callback is fired at each app startup and whenever a new token is generated.
      }
  
  
  }
  
  // [START ios_10_message_handling]
  @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("Message ID: \(messageID)")
          }
  
          // Print full message.
          print(userInfo)
  
          // Change this to your preferred presentation option
          completionHandler([])
      }
  
      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("Message ID: \(messageID)")
          }
  
          // Print full message.
          print(userInfo)
  
          completionHandler()
      }
  
  }
  </code></pre>
  
  <p>The certs and keys I downloaded/ generated are:<a href="https://i.stack.imgur.com/KYdUr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KYdUr.png" alt="enter image description here"></a>
  The Certificates, Identifiers &amp; Profiles section looks like this:
  <a href="https://i.stack.imgur.com/obrCO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/obrCO.png" alt="enter image description here"></a><a href="https://i.stack.imgur.com/Gssjg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Gssjg.png" alt="enter image description here"></a><a href="https://i.stack.imgur.com/28G9Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/28G9Y.png" alt="enter image description here"></a>
  In firebase's setting its looks like this:<a href="https://i.stack.imgur.com/pe1DT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pe1DT.png" alt="enter image description here"></a></p>