Xamarin SDK Reference
This topic explains how to use the Harness Feature Flags SDK in your Xamarin application.
This topic describes how to use the Harness Feature Flags SDK for your Xamarin application. You can use the Xamarin SDK for Android and iOS.
For getting started quickly, you can clone and run a sample application from the Xamarin Client Sample GitHub Repository.
Before You Begin
Make sure you read and understand the following:
Version
Latest SDK version can be found on GitHub Release Page
Prerequisites
Create a Xamarin application, or clone our sample application.
Create a Feature Flag on the Harness Platform. If you are following along with the SDK README sample code, make sure your flag is called
harnessappdemodarkmode.
Xamarin for Android
The Xamarin SDK uses a Harness binding library in a NuGet package for Android.
Install the SDK
To use this SDK for Android, you must provide Google GSON bindings, for example:
Then, install the SDK package in your application, for example:
Initialize the SDK
To initialize the Xamarin Android SDK, you need to:
Add your Client SDK key to connect to your Harness Environment.
Add a Target that you want to Evaluate against a Feature Flag.
(Optional) Configure the SDK options.
Complete the initialization with the SDK using the Listener, Client SDK Key, Target, and Configuration parameters you set.
For example:
Evaluate a Flag
Evaluating a Flag is when the SDK processes all Flag rules and returns the correct Variation of that Flag for the Target you provide.
If a matching Flag can’t be found, or the SDK can’t remotely fetch flags, the default value is returned.
There are different methods for the different Variation types and for each method you need to pass in:
Identifier of the Flag you want to evaluate
The default Variation
There are different methods for the different Flag Variation types:
Boolean Variation
Number Variation
String Variation
JSON Variation
For example:
Listen for events
Test your app is connected to Harness
When you receive a response showing the current status of your Feature Flag, go to the Harness Platform and toggle the Flag on and off. Then, check your app to verify if the Flag Variation displayed is updated with the Variation you toggled.
Close the SDK client
In most applications, you won't need to close the SDK client.
However, you should close the SDK client if:
Your application is about to terminate. Closing the client ensures that all associated resources are released.
You have determined that you do not need to evaluate flags again in your application lifecycle.
Xamarin for iOS
The Xamarin SDK uses a Harness binding library in a NuGet package for iOS.
Install the SDK
Install the SDK package in your application, for example:
Initialize the SDK
To initialize the Xamarin Android SDK, you need to:
Add your Client SDK key to connect to your Harness Environment.
Add a Target that you want to Evaluate against a Feature Flag.
(Optional) Configure the SDK options.
Complete the initialization with the SDK using the Listener, Client SDK Key, Target, and Configuration parameters you set.
For example:
Evaluate a Flag
Evaluating a Flag is when the SDK processes all Flag rules and returns the correct Variation of that Flag for the Target you provide.
If a matching Flag can’t be found, or the SDK can’t remotely fetch flags, the default value is returned.
There are different methods for the different Variation types and for each method you need to pass in:
Identifier of the Flag you want to evaluate
The default Variation
There are different methods for the different Variation types:
Boolean Variation
Number Variation
String Variation
JSON Variation
For example:
Listen for events
Test your app is connected to Harness
When you receive a response showing the current status of your Feature Flag, go to the Harness Platform and toggle the Flag on and off. Then, check your app to verify if the Flag Variation displayed is updated with the Variation you toggled.
Last updated
Was this helpful?