title: iOS Firebase Cloud Messaging Notifications not being received after using .p8 file
body: <p>I followed all the steps below and added the appropriate imports and code in <code>App Delegate</code>. I also made sure I allowed Notifications to be accepted when I ran the app.</p>
  
  <p><strong>Following the steps below, why is it that I can't receive the Notifications after I send one from the Firebase Cloud Messaging Console ?</strong></p>
  
  <ol>
  <li><p>In my Developer account I went to <code>Certificates, Identifiers &amp; Profiles</code></p></li>
  <li><p>Under <code>Keys</code>, I selected <code>All</code> and clicked the Add button (+) in the upper-right corner</p></li>
  <li><p>Under <code>Key Description</code>, I entered a unique name for the signing key</p></li>
  <li><p>Under <code>Key Services</code>, I selected the <code>APNs</code> checkbox, then clicked <code>Continue</code> then clicked <code>Confirm</code></p></li>
  <li><p>I copied the <code>Key ID</code> (used in step 7) and clicked <code>Download</code> to generate and download the <code>.p8</code> key</p></li>
  <li><p>I went to <code>Firebase</code>, clicked the <code>Gear Icon</code> > <code>Project Settings</code> > <code>Cloud Messaging</code> <strong>(not Grow > Cloud Messaging like step 10)</strong></p></li>
  <li><p>Under <code>iOS app configuration</code> > <code>APNs Authentication Key</code> I went to the first section <code>APNs Authentication Key</code> (NOT APNs Certificates), selected <code>Upload</code> and uploaded the <code>.p8</code> key, the <code>Key ID</code>, and my <code>Team Id</code>. The <code>teamId</code> is located in the <code>Membership</code> section and the keyId is the <code>xxxxxxx</code> part of the <code>xxxxxxx</code>.p8 file.</p></li>
  <li><p>In my Xcode project I went to <code>Capabilities</code> > <code>Background Modes</code>, turned it <code>On</code>, and checked <code>Remote Notifications</code></p></li>
  <li><p>Then I went to > <code>Push Notifications</code> and turned it <code>On</code> which automatically generated an <code>Entitlement Certificate</code> for the app (it's inside the project navigator)</p></li>
  <li><p>To send a notification in Firebase I went to <code>Grow</code> > <code>Cloud Messaging</code> > <code>Send Your First Message</code> > <code>1. Notification Text</code> entered some random String  > <code>2. Target</code> and selected my app's <code>bundleId</code> > <code>3. Scheduling Now</code> > 4. pressed Next > 5. selected <code>sound</code> and a <code>badge</code> > <code>Review</code></p></li>
  <li><p>In AppDelegate I added <code>import UserNotifications</code>, <code>import FirebaseMessaging</code>, <code>import Firebase</code>, registered for the <code>UNUserNotificationCenterDelegate</code> and added the code below.</p></li>
  <li><p>To set up the <a href="https://firebase.google.com/docs/auth/ios/phone-auth" rel="nofollow noreferrer">reCAPTCHA verification</a> I went to the <code>Blue Project Icon</code> > <code>Info</code> > <code>URL Types</code> then in the <code>URL Schemes</code> section (press the plus sign <code>+</code> if nothing is there), I entered in the <code>REVERSED_CLIENT_ID</code> from my <code>GoogleService-Info.plist</code></p></li>
  </ol>
  
  <p>I've added break points to all the print statements below and after I send a message from Firebase none of them get hit.</p>
  
  <pre><code>import UserNotifications
  import FirebaseMessaging
  import Firebase
  
  class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
  
      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -&gt; Bool {
  
          FirebaseApp.configure()
  
          UNUserNotificationCenter.current().delegate = self
  
          if #available(iOS 10.0, *) {
  
              UNUserNotificationCenter.current().requestAuthorization(options: [.sound,.alert,.badge]) {
              [weak self] (granted, error) in
  
                  if let error = error {
                      print(error.localizedDescription)
                      return
                  }
  
                  print("Success")
              }
              application.registerForRemoteNotifications()
  
          } else {
  
              let notificationTypes: UIUserNotificationType = [.alert, .sound, .badge]
              let notificationSettings = UIUserNotificationSettings(types: notificationTypes, categories: nil)
              application.registerForRemoteNotifications()
              application.registerUserNotificationSettings(notificationSettings)
          }
      }
  
      // MARK:- UNUserNotificationCenter Delegates
      func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  
          Messaging.messaging().setAPNSToken(deviceToken, type: MessagingAPNSTokenType.unknown)
  
          var token = ""
          for i in 0..&lt;deviceToken.count{
              token = token + String(format: "%02.2hhx", arguments: [deviceToken[i]])
          }
          print("Registration Succeded! Token: \(token)")
      }
  
      func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
          print("Notifcation Registration Failed: \(error.localizedDescription)")
      }
  
      func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -&gt; Void) {
  
          if let gcm_message_id = userInfo["gcm_message_id"]{
              print("MessageID: \(gcm_message_id)")
          }
  
          print(userInfo)
      }
  
      @available(iOS 10.0, *)
      func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -&gt; Void) {
  
          completionHandler(.alert)
  
          print("Handle push from foreground \(notification.request.content.userInfo)")
  
          let dict = notification.request.content.userInfo["aps"] as! NSDictionary
          let d = dict["alert"] as! [String:Any]
          let title = d["title"] as! String
          let body = d["body"] as! String
          print("Title:\(title) + Body:\(body)")
          showFirebaseNotificationAlertFromAppDelegate(title: title, message: body, window: self.window!)
      }
  
      func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -&gt; Void) {
  
          print("\(response.notification.request.content.userInfo)")
  
          if response.actionIdentifier == "yes"{
              print("True")
          }else{
              print("False")
          }
      }
  
      func showFirebaseNotificationAlertFromAppDelegate(title: String, message: String, window: UIWindow){
          let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
          let action = UIAlertAction(title: "OK", style: .default, handler: nil)
          alert.addAction(action)
          window.rootViewController?.present(alert, animated: true, completion: nil)
      }
  }
  </code></pre>
  
  <p>The message gets sent successfully as you can see in the below pic but I never receive it.</p>
  
  <p><a href="https://i.stack.imgur.com/qtwSx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qtwSx.png" alt="enter image description here"></a></p>