Configure White Label Sample App Compiler Directives
To use Compiler Directives configure directives for each Build Configuration in Xamarin / Visual Studio

Then add a ApiAccountSettings file to the PCL Project
TheAppsPajamas.White/Constants/ApiAccountSettings.cs
using System; namespace TheAppsPajamas.White.Constants { public static class ApiAccountSettings { #if BEAR public const string Username = "bear"; public const string Password = "NEb46BEq944Z9WKgJxvpCZa8Ckh578kR8WQ"; // In Visual Studio the inactive // configurations below are greyed out. // Like comments these are not // refactorable within the editor #elif BLUE public const string Username = "blue"; public const string Password = "ReNFRTEUWFYmhe9cfvmGkGwwp3V4trRDF9N"; #elif FLUFFY public const string Username = "fluffy"; public const string Password = "4nNeqf3jFaVMJE9HpsTsd5mkAPdWtk3aPQc"; #elif TEST public const string Username = "test"; public const string Password = "test"; #endif } }
You can now use the two constants when connecting to the API
- Username
- Password
TheAppsPajamas.White/Api/PrepareApiRequest.cs
using System; using System.Net.Http; using System.Net.Http.Headers; using System.Text; using TheAppsPajamas.White.Constants; namespace TheAppsPajamas.White.Api { public partial class ApiClient { partial void PrepareRequest( HttpClient client, HttpRequestMessage request, string url ) { // Xamarin Studio may detect ambiguity // warnings in the editor, but at compile // time any ambiguity is resolved var byteArray = Encoding.UTF8.GetBytes( String.Format("{0}:{1}", ApiAccountSettings.Username, ApiAccountSettings.Password )); client.DefaultRequestHeaders .Authorization = new AuthenticationHeaderValue( "Basic", Convert.ToBase64String(byteArray) ); } } }
info
This is our second favourite option. The difficulty in refactoring, or reliably adding new constants is our biggest issue with it