title: FCM on iOS An error occured on client IDB480752 while executing a reply for topic xvs/idb/4.8.0.752/stop-app
body: <p>I added firecloud messaging to my iOS app as described here <a href="https://components.xamarin.com/gettingstarted/firebaseioscloudmessaging#subscribe-the-client-app-to-a-topic" rel="nofollow noreferrer">https://components.xamarin.com/gettingstarted/firebaseioscloudmessaging#subscribe-the-client-app-to-a-topic</a> and it seems to work fine for both foreground and background notificaitons on initial run of the app. I am actually using the nuget Xamarin.Firebase.iOS.CloudMessaging not the component. </p>
  
  <p>When I open the app a second time after having sent at least one push notification I get this error at launch in the debug output. </p>
  
  <p><strong>An error occured on client IDB480752 while executing a reply for topic xvs/idb/4.8.0.752/stop-app</strong></p>
  
  <p>Looking at the ide logs gives a little more detail.</p>
  
  <p><em>NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)
  2018-02-16 16:47:54.525 RecoveryConnect_Mobile_PCLiOS[1018:3202793]  Encounter network error. Code, error: -1200, Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo={NSURLErrorFailingURLPeerTrustErrorKey=, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9802, NSErrorPeerCertificateChainKey=(
      "",
      ""
  ), NSUnderlyingError=0x10b0f5190 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, kCFStreamPropertySSLPeerTrust=, _kCFNetworkCFStreamSSLErrorOriginalValue=-9802, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9802, kCFStreamPropertySSLPeerCertificates=(
      "",
      ""
  )}}, NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSErrorFailingURLKey=<a href="https://play.googleapis.com/log" rel="nofollow noreferrer">https://play.googleapis.com/log</a>, NSErrorFailingURLStringKey=<a href="https://play.googleapis.com/log" rel="nofollow noreferrer">https://play.googleapis.com/log</a>, NSErrorClientCertificateStateKey=0}
  The app has been terminated.
  Failed to Stop app:  An error occured on client IDB480752 while executing a reply for topic xvs/idb/4.8.0.752/stop-app
  The app has been terminated.</em></p>
  
  
  
  <pre class="lang-cs prettyprint-override"><code> public partial class AppDelegate : 
      global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate, 
      IUNUserNotificationCenterDelegate, IMessagingDelegate
  {
      global::Xamarin.Forms.Forms.Init();
      global::Xamarin.FormsMaps.Init();
      App.BuildNumber = NSBundle.MainBundle.InfoDictionary[new 
      NSString("CFBundleVersion")].ToString();
      LoadApplication(new App());
  
      RegisterForPushNotifications();
  
      return base.FinishedLaunching(app, options);
  
  }
  
  public override void DidEnterBackground(UIApplication uiApplication)
  {
      //Messaging.SharedInstance.ShouldEstablishDirectChannel = false;
      Messaging.SharedInstance.Disconnect();
  }
  
  public override void OnActivated(UIApplication uiApplication)
  {
      ConnectFCM();
      UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
      base.OnActivated(uiApplication);
  }
  
  
  
  
      private void RegisterForPushNotifications()
      {
          try
          {
              Firebase.Core.App.Configure();
  
              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();
  
              Firebase.InstanceID.InstanceId.Notifications.ObserveTokenRefresh((sender, e) =&gt;
              {
                  var newToken = Firebase.InstanceID.InstanceId.SharedInstance.Token;
  
                  var FCMTokenRegistration = new Models.Model_FCMToken(newToken);
                  FCMTokenRegistration.StoreToken();
                  // if you want to send notification per user, use this token
                  System.Diagnostics.Debug.WriteLine(newToken);
  
                  ConnectFCM();
              });
          }
          catch(System.Exception ex)
          {
              Helpers.Helper_ErrorHandling.SendErrorToServer(ex);
          }
  
  
  
      }
  
      private void ConnectFCM()
      {
          Messaging.SharedInstance.Connect(error =&gt; {
              if (error != null)
              {
                  // Handle if something went wrong while connecting
              }
              else
              {
                  // Let the user know that connection was successful
              }
          });
  
      }
  
      public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action&lt;UIBackgroundFetchResult&gt; completionHandler)
      {
          // If you are receiving a notification message while your app is in the background,
          // this callback will not be fired 'till the user taps on the notification launching the application.
  
          // Do your magic to handle the notification data
          System.Console.WriteLine(userInfo);
      }
  
      // 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)
      {
          // Do your magic to handle the notification data
          System.Console.WriteLine(notification.Request.Content.UserInfo);
      }
  
      // Receive data message on iOS 10 devices.
      public void ApplicationReceivedRemoteMessage(RemoteMessage remoteMessage)
      {
          Console.WriteLine(remoteMessage.AppData);
      }
  
      [Export("userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:")]
      public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler)
      {
          // Do your magic to handle the notification data
          System.Console.WriteLine("");
      }
  
      public void DidRefreshRegistrationToken(Messaging messaging, string fcmToken)
      {
  
          var token = fcmToken;
          //var newToken = Firebase.InstanceID.InstanceId.SharedInstance.Token;
  
          //var FCMTokenRegistration = new Models.Model_FCMToken(newToken);
          //FCMTokenRegistration.StoreToken();
          //// if you want to send notification per user, use this token
          //System.Diagnostics.Debug.WriteLine(newToken);
  
          //ConnectFCM();
      }
  </code></pre>
  
  <p>I did try adding NSAppTransportSecurity for arbitrary loads with no avail.</p>