2016-10-15 3 views
0

XamarinのSharedProjectにApp Credentialを保存する方法はありますか?XamarinのSharedProjectにApp Credentialを保存

私はAndroidとiOS AppをXamarinで作成しました。私はSharedProjectを使ってコードを共有しています。それらの間に。今度は、共有プロジェクトクラスのトークンのようなAppクレデンシャルを保存する必要があります。

ご了承ください。

答えて

0

これにはXamarin.Authを使用できます。 https://developer.xamarin.com/recipes/cross-platform/xamarin-forms/general/store-credentials/

あなたはNuGet経由でインストールすることができます。Install-Package Xamarin.Auth

特定の小さなプラットフォームがあります。 AndroidのCreate機能ではコンテキストが必要です。

あなたは、Androidプロジェクトのプロパティで ANDROID定数に

  • 開いているプロジェクトのプロパティを定義する必要が
    class MyStorage 
    { 
        private readonly AccountStore _accountStore; 
    
        public MyStorage() 
        { 
         #if ANDROID 
         _accountStore = AccountStore.Create(Application.Context); 
         #else 
         _accountStore = AccountStore.Create(); 
         #endif 
        } 
    
        public void SaveCredentials(string userName, string token) 
        { 
         var account = new Account(userName); 
         account.Properties.Add("Token", token); 
         _accountStore.Save(account, "MyApp.MyStorage"); 
        } 
    } 
    

  • オープンビルド
  • 選択All Configurations
  • 場合は条件付きコンパイルシンボルにANDROIDを追加存在しない

enter image description here

関連する問題