title: Xamarin iOS present a different view controller when app returns from background
body: <p>The xamarin ios app which I am working on requires GPS to be always enabled. When the application is first installed the user gets a prompt to enable GPS however the user has the option to turn off location services at device level.  </p>
  
  <p>I would like my app to prompt(i.e.. NAG) user to enable gps. Hence, I created a new viewcontroller and the corresponding xib file.  The xib file looks like this</p>
  
  <p><a href="https://i.stack.imgur.com/2BbjV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2BbjV.png" alt="New View Controller"></a></p>
  
  <p>I have added the following code in the WillEnterForeground and there are no errors however the view is presented but if the gps is enabled this view is shown not the previously active view. </p>
  
  <pre><code>     public override void WillEnterForeground(UIApplication application)
              {
                  Console.WriteLine("App will enter foreground");
                  if (CLLocationManager.Status == CLAuthorizationStatus.Denied 
                      || CLLocationManager.Status == CLAuthorizationStatus.Restricted
                      || CLLocationManager.Status == CLAuthorizationStatus.NotDetermined)
                  {
  
                      window = new UIWindow(UIScreen.MainScreen.Bounds);
  
                      var rootNavigationController = new UINavigationController();
                      rootNavigationController.PushViewController(new LocationServicesVerifyViewController(), false);
  window.RootViewController = rootNavigationController;
                      window.MakeKeyAndVisible();
  
                  }
              }
  </code></pre>
  
  <p>The idea is I will present this view when application is launched or when returns from background if Location services is not enabled.  </p>
  
  <p>Clicking on the Enable GPS Button will run the following code which will basically take the user to location section on the device.</p>
  
  <pre><code>            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
              {
                  NSString settingsString = UIApplication.OpenSettingsUrlString;
                  NSUrl url = new NSUrl(settingsString);
                  UIApplication.SharedApplication.OpenUrl(url);
              }
  </code></pre>
  
  <p>My class level declarations are</p>
  
  <pre><code>  // class-level declarations
          UIWindow window;
  </code></pre>
  
  <p>My current finished launching method looks like this</p>
  
  <pre><code>public override bool FinishedLaunching(UIApplication app, NSDictionary options)
  {
      AppDelegate.Self = this;
  
      window = new UIWindow(UIScreen.MainScreen.Bounds);
  
      var rootNavigationController = new UINavigationController();
      window.RootViewController = rootNavigationController;
  
      DataAccess.CheckDatabase();
  
      if (DataAccess.GetLicence().APIKey == "")
      {
          rootNavigationController.PushViewController(new LicenceActivationViewController(), false);
      }
      else
      {
          rootNavigationController.PushViewController(new JobListViewController(), false);
      }
  
      window.MakeKeyAndVisible();
  
      return true;
  
  }
  </code></pre>