title: Firebase Cloud Messaging iOS: No background push notification
body: <p>Using the newer Firebase cloud messaging with method swizzling i am successfully able to receive a payload in the <code>didReceiveRemoteNotification</code> method in my app delegate when my app is <em>foregrounded</em>. However i do not get any sort of payload and <code>didReceiveRemoteNotification</code> does not get called when my app is <em>backgrounded</em>, despite the api response that the message is successfully sent (see below)
  <br> Here is the request that i send to the FCM api to trigger a push notification  <code>https://fcm.googleapis.com/fcm/send</code></p>
  
  <pre><code>{
  "to": "{valid-registration-token}",
  "priority":"high", //others suggested setting priority to high would fix, but did not
    "notification":{
        "body":"Body3",
        "title":"test"  
   } 
  }
  </code></pre>
  
  <p><br> with response from FCM</p>
  
  <pre><code>{
        "multicast_id": 6616533575211076304,
        "success": 1,
        "failure": 0,
        "canonical_ids": 0,
        "results": [
          {
            "message_id": "0:1468906545447775%a4aa0efda4aa0efd"
          }
        ]
      }
  </code></pre>
  
  <p>Here is my appDelegate code</p>
  
  <pre><code>func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -&gt; Bool {
  
          Fabric.with([Crashlytics.self])
          FIRApp.configure()
  
          NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.tokenRefreshNotification),
                                                           name: kFIRInstanceIDTokenRefreshNotification, object: nil)
          return true
      }
  
  
  
      func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -&gt; Void) {
          // Let FCM know about the message for analytics etc.
          FIRMessaging.messaging().appDidReceiveMessage(userInfo)
  
          // Print full message.
          print("%@", userInfo)
  
          // handle your message
  
  //        let localNotification = UILocalNotification()
  //        localNotification.fireDate = NSDate()
  //        let notification = userInfo["notification"]!
  //        localNotification.alertBody = notification["body"] as? String
  //        localNotification.alertTitle = notification["title"] as? String
  //        localNotification.timeZone = NSTimeZone()
  //        application.scheduleLocalNotification(localNotification)
  
      }
  
      func tokenRefreshNotification(notification: NSNotification) {
          let refreshedToken = FIRInstanceID.instanceID().token()!
          print("InstanceID token: \(refreshedToken)")
          LoginVC.registerForPushNotifications()
          connectToFcm()
      }
  
  
      //foreground messages
      func applicationDidBecomeActive(application: UIApplication) {
          connectToFcm()
      }
  
      // [START disconnect_from_fcm]
      func applicationDidEnterBackground(application: UIApplication) {
          FIRMessaging.messaging().disconnect()
          print("Disconnected from FCM.")
      }
  
  
      func connectToFcm() {
          FIRMessaging.messaging().connectWithCompletion { (error) in
              if (error != nil) {
                  print("Unable to connect with FCM. \(error)")
              } else {
                  print("Connected to FCM.")
              }
          }
      }
  
  }
  </code></pre>
  
  <p>I call this code at a later flow in my app to ask for permissions</p>
  
  <pre><code>static func registerForPushNotifications() {
      let settings: UIUserNotificationSettings =
                  UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
              UIApplication.sharedApplication().registerUserNotificationSettings(settings)
              UIApplication.sharedApplication().registerForRemoteNotifications()
  }
  </code></pre>
  
  <p>Since i am able to receive notifications while app is foregrounded i assume this would allay all concerns that my apns certificates are not uploaded or that the registration token is incorrect. If that is not the case, please comment and i'll go down that rabbit hole again.
  There's probably something simple that i am overlooking, but how can i get the notifications to appear while the app is backgrounded? Thanks</p>