title: Xamarin iOS: FCM Notifications click event
body: <p>I have developed FCM notifications in Xamarin.iOS app. Now I need navigation on notifications click, Where I can handle that to go to specific screen/viewController of app</p>
  
  <p>My appDelegate Class with all overloaded methods </p>
  
  <pre><code>namespace edTheS
  {
      [Register("AppDelegate")]
      public class AppDelegate : UIApplicationDelegate,IUNUserNotificationCenterDelegate, IMessagingDelegate
      {        
  
          public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
          {
  
              LoginViewController loginCntl = new LoginViewController();
  
                  var loginCntl1 = new LoginViewController();
                  this.navCntl = new UINavigationController(loginCntl1);
                  this.navCntl.NavigationBarHidden = true;
                  Window.MakeKeyAndVisible();
               InstanceId.Notifications.ObserveTokenRefresh(TokenRefreshNotification);
  
              //Register your app for remote notifications.
              if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
              {
                  // iOS 10 or later
                  var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
                  UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) =&gt; {
                      Console.WriteLine(granted);
                  });
  
                  //For iOS 10 display notification (sent via APNS)
              UNUserNotificationCenter.Current.Delegate = this;
              //For iOS 10 data message (sent via FCM)
              Messaging.SharedInstance.RemoteMessageDelegate = this;
  
              }   
              else
              {
                  // iOS 9 or before
                  var allNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
                  var settings = UIUserNotificationSettings.GetSettingsForTypes(allNotificationTypes, null);
                  UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
              }
              UIApplication.SharedApplication.RegisterForRemoteNotifications();
              App.Configure();
              return true;
          }
  
        public override void OnResignActivation(UIApplication application)
       {
            // Invoked when the application is about to move from active to inactive state.
              // This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) 
              // or when the user quits the application and it begins the transition to the background state.
              // Games should use this method to pause the game.
       }
  
       public override void WillEnterForeground(UIApplication application)
          {
            // Called as part of the transiton from background to active state.
             // Here you can undo many of the changes made on entering the background.
        }
  
       public override void WillTerminate(UIApplication application)
        {
            // Called when the application is about to terminate. Save data, if needed. See also DidEnterBackground.
         }
  
  
          // You'll need this method if you set "FirebaseAppDelegateProxyEnabled": NO in GoogleService-Info.plist
          public override void RegisteredForRemoteNotifications (UIApplication application, NSData deviceToken)
          {
              SISConst.PushInfo = new PushNotification();
              SISConst.PushInfo.DeviceID = deviceToken.ToString();
              NSUserDefaults.StandardUserDefaults.SetString(deviceToken.ToString(),"dToken"); 
              InstanceId.SharedInstance.SetApnsToken (deviceToken, Firebase.InstanceID.ApnsTokenType.Sandbox);
  
              //InstanceId.SharedInstance.a
  
  
              #if DEBUG
              Firebase.InstanceID.InstanceId.SharedInstance.SetApnsToken(deviceToken, Firebase.InstanceID.ApnsTokenType.Sandbox);
  #endif
  #if RELEASE
              Firebase.InstanceID.InstanceId.SharedInstance.SetApnsToken(deviceToken, Firebase.InstanceID.ApnsTokenType.Prod);
  #endif
  
          }
  
  
       //public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
        //{
        //    Console.WriteLine("Failed to register for remote notifications {0}", error.LocalizedDescription);
        //}
  
  
        //FCM-- This method calling when notifications delivering
        public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action&lt;UIBackgroundFetchResult&gt; completionHandler)
         {
  
              Messaging.SharedInstance.AppDidReceiveMessage(userInfo);
  
              // Generate custom event
              NSString[] keys = { new NSString("Event_type") };
              NSObject[] values = { new NSString("Recieve_Notification") };
              var parameters = NSDictionary&lt;NSString, NSObject&gt;.FromObjectsAndKeys(keys, values, keys.Length);
              //Messaging.SharedInstance.AppDidReceiveMessage(userInfo);
              string studentId = string.Empty, OrgNameSubTtl = string.Empty, moduleTitle = string.Empty, bodyText = string.Empty;
              // Send custom event
              Firebase.Analytics.Analytics.LogEvent("CustomEvent", parameters);
  
              if (application.ApplicationState == UIApplicationState.Active)
              {
  
                  //var title = notification.Request.Content.Title;      
                  var remotePushData = userInfo.ToDictionary(i =&gt; i.Key.ToString(), i =&gt; i.Value.ToString());
  
                  ScheduleNotification(moduleTitle.ToString(),OrgNameSubTtl.ToString(),bodyText.ToString());
              }
  
              else if(application.ApplicationState == UIApplicationState.Background)
              {
  
                  var remotePushData = userInfo.ToDictionary(i =&gt; i.Key.ToString(), i =&gt; i.Value.ToString());
  
                  ScheduleNotification(moduleTitle.ToString(), OrgNameSubTtl.ToString(), bodyText.ToString());
              }
              else if(application.ApplicationState == UIApplicationState.Inactive)
              {
  
                  var remotePushData = userInfo.ToDictionary(i =&gt; i.Key.ToString(), i =&gt; i.Value.ToString());
  
                  ScheduleNotification(moduleTitle.ToString(), OrgNameSubTtl.ToString(), bodyText.ToString());
              }
  
          }
  
  
          //FCM
          // To receive notifications in foreground on iOS 10 devices.
          [Export("userNotificationCenter:willPresentNotification:withCompletionHandler:")]
          public void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action&lt;UNNotificationPresentationOptions&gt; completionHandler)
          {
              string studentId = string.Empty, OrgNameSubTtl = string.Empty,moduleTitle=string.Empty,bodyText=string.Empty; 
              //var title = notification.Request.Content.Title;      
              var remotePushData = notification.Request.Content.UserInfo.ToDictionary(i =&gt; i.Key.ToString(), i =&gt; i.Value.ToString());
  
              ScheduleNotification(moduleTitle,OrgNameSubTtl,bodyText);
          }
  
   //Workaround for handling notifications in background for iOS 10
          [Export ("userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:")]
  
          public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler)
          {
              Console.WriteLine("Notifications clicked......");
          }
  
         public override void DidEnterBackground(UIApplication application)
         {
              //FCM
              Messaging.SharedInstance.ShouldEstablishDirectChannel = false;
              Console.WriteLine("Disconnected from FCM");
          }
  
          void ScheduleNotification(string title,string OrgSubtitle,string body)
          {
              //Create content
              var content = new UNMutableNotificationContent();
              content.Title = title;
              content.Subtitle = OrgSubtitle;
              content.Body = body;
              content.Badge = 0;
              content.CategoryIdentifier = "categoryID";
              content.Sound = UNNotificationSound.Default;
  
  
              // Fire trigger in one seconds
              var trigger = UNTimeIntervalNotificationTrigger.CreateTrigger(1, false);
  
              var requestID = "customNotification";
              var request = UNNotificationRequest.FromIdentifier(requestID, content, trigger);
  
              // This is the line that does the trick
              UNUserNotificationCenter.Current.Delegate = new CustomUNUserNotificationCenterDelegate();
  
              UNUserNotificationCenter.Current.AddNotificationRequest(request, (err) =&gt; {
                  if (err != null)
                  {
                      // Report error
                      System.Console.WriteLine("Error: {0}", err);
                  }
                  else
                  {
                      // Report Success
                      System.Console.WriteLine("Notification Scheduled: {0}", request);
                  }
              });
          }
      }
  }
  </code></pre>
  
  <p>From the above code none of method calling on notification click.
  Please suggest me better way</p>
  
  <p>CustomUNUserNotificationCenterDelegate is separate class </p>
  
  <pre><code>public class CustomUNUserNotificationCenterDelegate : UNUserNotificationCenterDelegate
      {
          string studentId = string.Empty, OrgNameSubTtl = string.Empty,moduleNmae=string.Empty,bodyText=string.Empty; 
  
          public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler)
          {
              // Here you handle the user taps
              completionHandler();
  
              var remotePushData = response.Notification.Request.Content.UserInfo.ToDictionary(i =&gt; i.Key.ToString(), i =&gt; i.Value.ToString());
  
          }
          public override void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action&lt;UNNotificationPresentationOptions&gt; completionHandler)
          {
              completionHandler(UNNotificationPresentationOptions.Alert | UNNotificationPresentationOptions.Sound | UNNotificationPresentationOptions.Badge);
  
          }
  </code></pre>