title: Push notifications in iOS suddenly not delivering via Firebase
body: <p>Recently I stopped receiving Firebase Cloud Messaging APNs notifications. I decided to update to latest version of Firebase pods and my <code>AppDelegate.swift</code> had a few functions deprecated so it currently looks like this now:</p>
  <pre><code>import UIKit
  import SwiftyJSON
  import IQKeyboardManagerSwift
  import Firebase
  import FirebaseInstanceID
  import FirebaseMessaging
  import UserNotifications
  import AVFoundation
  import Crittercism
  
  
  @UIApplicationMain
  
  class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate, UNUserNotificationCenterDelegate {
      
      var window: UIWindow?
      var isPulltoRefreshInProgress: Bool = Bool(false)
      
      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -&gt; Bool {
          
          Crittercism.enable(withAppID: Config.sharedInstance.apteligentAppID())
  
          //To find Home Directory
          print(&quot;Home Directory - \(NSHomeDirectory())&quot;)
          IQKeyboardManager.shared.enable = true
          IQKeyboardManager.shared.enableAutoToolbar = false
          IQKeyboardManager.shared.shouldShowToolbarPlaceholder = false
          // IQKeyboardManager.shared.shouldResignOnTouchOutside = true
        //  UIApplication.shared.statusBarStyle = .lightContent
          configureForPushNotification()
          registrationForNotification(application: application )
          self.startOver()
          
          return true
      }
      
      func registrationForNotification(application: UIApplication) {
          // iOS 10 support
          if #available(iOS 10, *) {
              DLog(&quot;registrationForNotification&quot;)
              UNUserNotificationCenter.current().delegate = self
              UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .alert, .sound]){ (granted, error) in }
              application.registerForRemoteNotifications()
          }
          else {
              application.registerForRemoteNotifications(matching: [.badge, .sound, .alert])
          }
      }
      
      func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -&gt; Void) {
          
          Tokens.sharedInstance.isNotificationCame = true
          NotificationCenter.default.post(name: NSNotification.Name(NotificationCenterIDs.kPushNotificationReceivedNotification), object:self)
          
          if application.applicationState == UIApplication.State.active {
              DLog(&quot;App is in foreground when notification received&quot;)
              // app was already in the foreground
          } else {
              DLog(&quot;App was just brought from background to foreground via PUSH&quot;)
              // app was just brought from background to foreground via PUSH
              self.startOver()
          }
      }
      
      func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -&gt; Void) {
  //      let application = UIApplication.shared
        
  //      if(application.applicationState == .active){
  //        DLog(&quot;user tapped the notification bar when the app is in foreground&quot;)
          if let window = self.window {
              if let viewController = UIStoryboard(name: StoryboardControllerIDs.kStoryboardId, bundle: nil).instantiateViewController(withIdentifier: StoryboardController.kNotificationsViewController) as? NotificationsViewController{
                  if let rootViewController = window.rootViewController as? UINavigationController{
  //                    DLog(&quot;Root: &quot; + String(describing: type(of: rootViewController)))
                      Tokens.sharedInstance.isNotificationCame = true
                      rootViewController.pushViewController(viewController, animated: true)
                  }
              }
          }
  //      }
        
  //      if(application.applicationState == .inactive)
  //      {
  //        DLog(&quot;user tapped the notification bar when the app is in background&quot;)
  //      }
        
        /* Change root view controller to a specific viewcontroller */
        // let storyboard = UIStoryboard(name: &quot;Main&quot;, bundle: nil)
        // let vc = storyboard.instantiateViewController(withIdentifier: &quot;ViewControllerStoryboardID&quot;) as? ViewController
        // self.window?.rootViewController = vc
        
        completionHandler()
      }
      
      func configureForPushNotification() {
          var fileName : String = &quot;GoogleServiceQA-Info&quot;
          
          let currentConfiguration = Bundle.main.object(forInfoDictionaryKey: &quot;Config&quot;)! as! String
          
          if currentConfiguration.lowercased() == &quot;production&quot; {
              fileName = &quot;GoogleServiceProd-Info&quot;
          } 
          
          let filePath = Bundle.main.path(forResource: fileName, ofType: &quot;plist&quot;)!
          let options = FirebaseOptions(contentsOfFile: filePath)
          FirebaseApp.configure(options: options!)
          Messaging.messaging().delegate = self
          
  //        if let refreshedToken = InstanceID.instanceID().token() {
  //            print(&quot;InstanceID token: \(refreshedToken)&quot;)
  //            DeviceTokenConstants.deviceToken = refreshedToken
  //        }
          InstanceID.instanceID().instanceID { (result, error) in
              if let error = error {
                  DLog(&quot;Error fetching remote instange ID: \(error)&quot;)
              } else if let result = result {
                  DLog(&quot;configureForPushNotification - Remote instance ID token: \(result.token)&quot;)
                  DeviceTokenConstants.deviceToken = result.token
              }
          }
          
          NotificationCenter.default.addObserver(self, selector:
              #selector(tokenRefreshNotification), name:
              NSNotification.Name.InstanceIDTokenRefresh, object: nil)
      }
      
      func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
          //Getting errors in Xcode10 for iOS12
          let hexString = deviceToken.map { String(format: &quot;%02.2hhx&quot;, $0) }.joined()
          DLog(&quot;===DEVICE-TOKEN: \(hexString)&quot;)
          // In debug mode
          Messaging.messaging().apnsToken = deviceToken
          Messaging.messaging().setAPNSToken(deviceToken, type: .sandbox)
          Messaging.messaging().setAPNSToken(deviceToken, type: .prod)
          // In release mode
  //        InstanceID.instanceID().setAPNSToken(deviceToken, type: InstanceIDAPNSTokenType.prod)
      }
      
      // This method will be called when app received push notifications in foreground
      func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -&gt; Void)
      {
          completionHandler([.alert, .badge, .sound])
      }
      
      func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
          print(&quot;Firebase registration token: \(fcmToken)&quot;)
          DeviceTokenConstants.deviceToken = fcmToken
          FireBaseToken.didReceived = true
      }
      
      @objc func tokenRefreshNotification(_ notification: Notification) {
          
          InstanceID.instanceID().instanceID { (result, error) in
          if let error = error {
              print(&quot;Error fetching remote instange ID: \(error)&quot;)
          } else if let result = result {
              print(&quot;tokenRefreshNotification - Remote instance ID token: \(result.token)&quot;)
              DeviceTokenConstants.deviceToken = result.token
              let dataDict:[String: String] = [&quot;token&quot;: result.token]
              NotificationCenter.default.post(name: Notification.Name(&quot;FCMToken&quot;), object: nil, userInfo: dataDict)
           }
          }
  
  //        Deprecated code
  //        if let refreshedToken = InstanceID.instanceID().token() {
  //            print(&quot;InstanceID token: \(refreshedToken)&quot;)
  //            DeviceTokenConstants.deviceToken = refreshedToken
  //        }
          // Connect to FCM since connection may have failed when attempted before having a token.
  //        connectToFcm()
      }
  </code></pre>
  <p>Is there something in this code that may prevent the notification from being delivered or is this an external issue outside of the iOS app? I am able to see tokens being printed in my console for the device token and fcm token, so I feel that the setup in the iOS app is not the issue. I ensured that the app notifications were not disabled in my iPhone.</p>