Skip to content

Initial SDK setup

This reference article covers how to install the Braze SDK for Xamarin. Installing the Braze SDK will provide you with basic analytics functionality as well as working in-app messages with which you can engage your users.

Android

Step 1: Get the Xamarin binding

A Xamarin binding is a way to use native libraries in Xamarin apps. The implementation of a binding consists of building a C# interface to the library, and then using that interface in your application. See the Xamarin documentation.

There are two ways to include the Braze SDK binding:

Option 1: Nuget

The simplest integration method involves getting the Braze SDK from the Nuget.org central repository. In the Visual Studio sidebar, right click Packages folder and click Add Packages.... Search for ‘Braze’ and install the AppboyPlatform.AndroidBinding package into your project.

Option 2: Source

The second integration method is to include the binding source. Under appboy-component\src\android you will find our binding source code; adding a project reference to the AppboyPlatform.XamarinAndroidBinding.csproj in your Xamarin application will cause the binding to be built with your project and provide you access to the Braze Android SDK.

The Braze Nuget package depends on the Xamarin.Android.Support.v4 Nuget package.

Step 2: Configure the Braze SDK in braze.xml

Now that the libraries have been integrated, you have to create an braze.xml file in your project’s Resources/values folder. The contents of that file should resemble the following code snippet:

Be sure to substitute REPLACE_WITH_YOUR_API_KEY with the API key located at Settings > API Keys in the Braze dashboard.

1
2
3
4
5
6
7
8
9
    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    <string name="com_braze_api_key">REPLACE_WITH_YOUR_API_KEY</string>
    <string translatable="false" name="com_braze_custom_endpoint">YOUR_CUSTOM_ENDPOINT_OR_CLUSTER</string>
    <string-array name="com_braze_internal_sdk_metadata">
      <item>XAMARIN</item>
      <item>NUGET</item>
    </string-array>
    </resources>

If you are including the binding source manually, remove <item>NUGET</item> from your code.

Step 3: Add required permissions to Android manifest

Now that you’ve added your API key, you need to add the following permissions to your AndroidManifest.xml file:

1
2
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Step 4: Tracking user sessions and registering for in-App messages

To enable user session tracking and register your app for in-app messages, add the following call to the OnCreate() lifecycle method of the Application class in your app:

1
RegisterActivityLifecycleCallbacks(new BrazeActivityLifecycleCallbackListener());

SDK integration complete

You should now be able to launch your application and see sessions being logged to the Braze dashboard (along with device information and other analytics).

Consult the Android integration instructions for a more in-depth discussion of best practices for the basic SDK integration.

iOS

Step 1: Get the Xamarin binding

A Xamarin binding is a way to use native libraries in Xamarin apps. The implementation of a binding consists of building a C# interface to the library and then using that interface in your application.

There are two ways to include the Braze SDK binding.

Option 1: Nuget

The simplest integration method involves getting the Braze SDK from the Nuget.org central repository. In the Visual Studio sidebar, right-click Packages folder and click Add Packages.... Search for ‘Braze’ and install the AppboyPlatformXamariniOSBinding package into your project.

Option 2: Source

The second integration method is to include the binding source. In our GitHub repository you will find our binding source code; adding a project reference to the AppboyPlatformXamariniOSBinding.csproj in your Xamarin application will cause the binding to be built with your project and provide you access to the Braze iOS SDK. Make sure AppboyPlatformXamariniOSBinding is showing in your project’s “Reference” folder.

Step 2: Update your app delegate and declare Xamarin usage

Within your AppDelegate.cs file, add the following snippet within your FinishedLaunching method:

Be sure to update YOUR-API-KEY with the correct value from the Developer Console page.

1
2
3
4
// C#
 Appboy.StartWithApiKey ("YOUR-API-KEY", UIApplication.SharedApplication, options);
 Appboy.SharedInstance.SdkFlavor = ABKSDKFlavor.Xamarin;
 Appboy.SharedInstance.AddSdkMetadata(new []{ ABKSdkMetadata.ABKSdkMetadataXamarin, ABKSdkMetadata.ABKSdkMetadataNuGet });

If you are including the binding source manually, remove ABKSdkMetadata.ABKSdkMetadataNuGet from your code.

Implementation Example

See the AppDelegate.cs file in the TestApp.XamariniOS sample app.

Step 3: Add your SDK endpoint to your info.plist file

Within your Info.plist file, add the following snippet:

Be sure to update YOUR-SDK-ENDPOINT with the correct value from your Settings page.

1
2
3
4
5
6
// C#
<key>Braze</key>
<dict>
 <key>Endpoint</key>
 <string>YOUR-SDK-ENDPOINT</string>
</dict>

You can optionally include verbose logging by including the following snippet:

1
2
3
4
5
6
7
8
// C#
<key>Braze</key>
<dict>
 <key>LogLevel</key>
 <string>0</string>
 <key>Endpoint</key>
 <string>YOUR-SDK-ENDPOINT</string>
</dict>

Note that prior to Braze iOS SDK v4.0.2, the dictionary key Appboy must be used in place of Braze.

SDK integration complete

Braze should now be collecting data from your application and your basic integration should be complete. See the following articles in order to enable custom event tracking, push messaging, and the complete suite of Braze features.

Our current public Xamarin binding for the iOS SDK does not connect to the iOS Facebook SDK (linking social data) and does not include sending the IDFA to Braze.

HOW HELPFUL WAS THIS PAGE?
New Stuff!