ios 10 Firebase Push Notification delegate method not called in background mode
<p>I have been struggling with this problem for days and I have looked at every post about this and nothing works.</p>

<p>I am using FCM (Firebase Cloud Messaging). FCM talks directly to the app when in foreground, but it will use APNS when the app is in background.</p>

<p>I am trying to call a method everytime the app got notification by calling the method in the push notification's delegate function</p>

<p>I have these 2 delegate functions:
<code>func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -&gt; Void)
</code>
and
<code>
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -&gt; Void)
</code>
which does not get called in background, according to apple documentation.</p>

<p>I also have this function which I believe should get called in the background but it does not.
<code>func application(_ application: UIApplication,didReceiveRemoteNotification userInfo: [AnyHashable: Any],fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -&gt; Void)</code></p>

<p>I have all of these functions in ViewController</p>

<p>In background mode, I get banner notifications, but none of the delegate is called. Is there any way to make any of them work in the background, if not what should I do?
In addition I also get this error : <code>&lt;FIRMessaging/WARNING&gt; FIRMessaging receiving notification in invalid state 2</code> in the log everytime I send a payload while the app is in the background.</p>

<p>Here is the payload that I send using postmate:</p>

<p><code>
{
    "priority":"high",
    "notification":{
        "sound": "default",
        "badge": "1",
        "title":"mytitle",
        "body":"mybody",
        "message":"Hello"
    },
   "content_available":true,
   "to" : "/topics/myTopic"
}
</code>
I already turned on push notification in capabilities and checked push notification in background modes under capabilities.</p>

<p>I use Xcode 8 and have been testing on iphone 6 iOS 10.0.2</p>