title: Write device platform specific code in Xamarin.Forms
body: <p>I have the following <code>Xamarin.Forms.ContentPage</code> class structure</p>
  
  <pre><code>public class MyPage : ContentPage
  {
      public MyPage()
      {
          //do work to initialize MyPage 
      }
  
      public void LogIn(object sender, EventArgs eventArgs)
      {
          bool isAuthenticated = false;
          string accessToken = string.Empty;
  
          //do work to use authentication API to validate users
  
          if(isAuthenticated)
          {
              //I would to write device specific code to write to the access token to the device
              //Example of saving the access token to iOS device
              NSUserDefaults.StandardUserDefaults.SetString(accessToken, "AccessToken");
  
              //Example of saving the access token to Android device
              var prefs = Application.Context.GetSharedPreferences("MySharedPrefs", FileCreationMode.Private);
              var prefsEditor = prefs.Edit();
  
              prefEditor.PutString("AccessToken", accessToken);
              prefEditor.Commit();
          }
      }
  }
  </code></pre>
  
  <p>I would like to write platform specific code in the <code>MyPage</code> <code>LogIn</code> method to save the access token based on which device OS they are using my application on.</p>
  
  <p>How do I only run device specific code when the user uses my application on their device?</p>