title: How to ignore a remote/push notification while app is on background/terminated
body: <p>Technologies Used:</p>
  
  <ul>
  <li><a href="https://firebase.google.com/products/cloud-messaging/" rel="nofollow noreferrer">Firebase Cloud Messaging</a></li>
  <li>Swift 3.2</li>
  <li>Xcode 9.2</li>
  </ul>
  
  <p>To give you a background here's the data I'm sending via FCM on an api server</p>
  
  <pre><code>{
  
      "priority": "high",
      "content_available": true,
      "alert": true,
      "sound": true,
      "registration_ids": [
           "&lt;SOME_ID_HERE&gt;", 
           "&lt;SOME_ID_HERE&gt;"
      ],
      "notification": {
          "title": "SOME TITLE",
          "body": "SOME BODY"
      },
      "data": {
          "some_key": "some_value",
          "some_key2": "some_value2"
      }
  }
  </code></pre>
  
  <p>This is being received by the app correctly, and I'm correctly using these methods in a correct manner</p>
  
  <pre><code>application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -&gt; Void)
  
  messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage)
  
  messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String)
  
  userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -&gt; Void)
  
  userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -&gt; Void)
  </code></pre>
  
  <p>Is there a way to somehow ignore a push notification when the app is in background/terminated with this sample code? </p>
  
  <pre><code>func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -&gt; Void) {
      switch application.applicationState {
      case .inactive, .background:
          // Tell Firebase that we recieved the Push Notification
          self.messaging.appDidReceiveMessage(userInfo)
  
          // `PushNotification` is a model that parses the `userInfo` dictionary
          guard let pushNotification: PushNotification = PushNotification(userInfo) else {
              return // end code execution cause push cannot be parsed
          }
  
          if pushNotification.isSomeKindOfThing {
              // ignore
          } else {
              // do nothing so it will show
          }
      case .active:
          // handle when application is active
      }
  }
  </code></pre>
  
  <p>What I'm aiming for is that when I receive a push notification I'm able to either ignore it depending on what is in the <code>"data"</code> key.</p>