Schreiben Sie plattformspezifischen Code in Xamarin.Forms

Habe ich Folgendes Xamarin.Forms.ContentPage Klasse Struktur

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();
        }
    }
}

Möchte ich schreiben, Plattform-spezifischen code, in der MyPage LogIn - Methode zum speichern der access-token-basierend auf dem Gerät, OS, die Sie mit meiner Bewerbung.

Wie kann ich nur ausführen, Geräte-spezifischer code, wenn der Benutzer meine Anwendung auf Ihrem Gerät?

InformationsquelleAutor der Frage Michael Kniskern | 2014-06-16

Schreibe einen Kommentar