title: Conditional handling Firebase push notifications
body: <p>I have a Xamarin.Forms app that supports Android and iPhone. The app sends and receives push notifications using Firebase for Android and Azure Notification Hub for iOS. If the app sends a notification from the sender's phone, multiple people in the group receive it and can handle it. But it is not what we need. I want only the first receiver to handle the notification, and the others should ignore it. Is there a good way to implement it?</p>
  <p>Here is my code that handles push notifications on Android:</p>
  <pre><code>[Service]
  [IntentFilter(new[] { &quot;com.google.firebase.MESSAGING_EVENT&quot; })]
  public class FirebaseService : FirebaseMessagingService
  {
      public override void OnMessageReceived(RemoteMessage message)
      {
          try
          {
              base.OnMessageReceived(message);
  
              string messageBody = message.GetNotification()?.Body;
  
              VideoCallMessage videoCallMessage = JsonConvert.DeserializeObject&lt;VideoCallMessage&gt;(messageBody);
  
              if (App.UserContext.IsEmployee)
              {
                  // convert the incoming message to a local notification
                  SendLocalNotification(messageBody);
              }
          }
          catch (Exception ex)
          {
              Log.Debug(&quot;FirebaseService.OnMessageReceived()&quot;, $&quot;Exception in OnMessageReceived(). ErrorMessage: {ex.Message}, Stack Trace: {ex.StackTrace}&quot;);
  
              Microsoft.AppCenter.Crashes.Crashes.TrackError(ex); // Report the exception to App Center
          }
      }
  </code></pre>
  <p>For iOS in Delegate.cs:</p>
  <pre><code>    [Export(&quot;userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:&quot;)]
      public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler)
      {
          completionHandler();
  
          NSDictionary userInfo = response.Notification.Request.Content.UserInfo;
          ProcessNotification(userInfo);
      }
  
      [Export(&quot;userNotificationCenter:willPresentNotification:withCompletionHandler:&quot;)]
      public void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action&lt;UNNotificationPresentationOptions&gt; completionHandler)
      {
          completionHandler(UNNotificationPresentationOptions.Sound | UNNotificationPresentationOptions.Alert);
  
          NSDictionary userInfo = notification.Request.Content.UserInfo;
          ProcessNotification(userInfo);
      }
  </code></pre>