For the complete documentation index, see llms.txt. This page is also available as Markdown.

Xamarin SDK Reference

This topic explains how to use the Harness Feature Flags SDK in your Xamarin application.

NOTE

This SDK is not currently supported on Harness Self-Managed Enterprise Edition (on premises).

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

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:

  1. Add your Client SDK key to connect to your Harness Environment.

  2. Add a Target that you want to Evaluate against a Feature Flag.

  3. (Optional) Configure the SDK options.

  4. 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.

NOTE

The SDK must run for at least 60 seconds before it sends metrics. Please ensure metrics have not been disabled in the SDK.

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.

IMPORTANT

The SDK does not evaluate flags after the client is closed.

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:

  1. Add your Client SDK key to connect to your Harness Environment.

  2. Add a Target that you want to Evaluate against a Feature Flag.

  3. (Optional) Configure the SDK options.

  4. 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?