Initial SDK Setup

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.

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 Bindings 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 found here. In our github repo 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. Please make sure AppboyPlatformXamariniOSBinding is showing in your project’s “Reference” folder.

Project Reference

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 your App Settings page.

 Appboy.StartWithApiKey ("YOUR-API-KEY", UIApplication.SharedApplication, options);
 Appboy.SharedInstance.SdkFlavor = ABKSDKFlavor.Xamarin;

Implementation Example

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

SDK Integration Complete

Braze should now be collecting data from your application and your basic integration should be complete. Please see the following sections in order to enable custom event tracking, push messaging, the news-feed 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.

Push Notifications

See the iOS integration instructions for information about setting up your application with push and storing your credentials on our server.

Integration

Requesting Push Permissions

Set up push permissions by adding the following code to the FinishedLaunching section of your AppDelegate.cs:

UIUserNotificationSettings settings = UIUserNotificationSettings.GetSettingsForTypes (UIUserNotificationType.Badge | UIUserNotificationType.Alert | UIUserNotificationType.Sound, null);
UIApplication.SharedApplication.RegisterForRemoteNotifications ();
UIApplication.SharedApplication.RegisterUserNotificationSettings (settings);

If you’ve implemented a custom push opt-in prompt, make sure that you’re calling the above code EVERY time the app runs after they grant push permissions to your app. Apps need to reregister with APNs as device tokens can change arbitrarily.

Registering Push Tokens

Register for your push tokens by adding the following code in the RegisteredForRemoteNotifications method of your AppDelegate.cs:

Appboy.SharedInstance ().RegisterPushToken (deviceToken.ToString ());

Enabling Push Analytics

Enable open tracking on push notifications by adding the following code to the DidReceiveRemoteNotification method of your AppDelegate.cs:

public override void DidReceiveRemoteNotification (UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
  {
    Appboy.SharedInstance ().RegisterApplicationWithFetchCompletionHandler(application, userInfo, completionHandler);
  }

Badge Count

If badge counts are enabled, Braze will display a badge when a customer has unread notifications. By default, this number is 1. Braze will only clear the badge count when the app is opened directly from an Braze push notification. To clear the badge count, you can refer to the Xamarin documentation and use the following code:

Xamarin C#

UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;

In-App Messages

In-App messages will work by default if you’ve included the Appboy.bundle folder in your application. On Xamarin we don’t currently support In-App message custom styling. If you would like to customize your in-app message UI, please implement the ABKInAppMessageControllerDelegate method ABKInAppMessageViewController InAppMessageViewControllerWithInAppMessage(ABKInAppMessage inAppMessage); and return your custom view controller. That will make sure Braze passes you the in-app message object rather than displaying it for you. You will then have the option of displaying the in-app message object’s content manually.

See the iOS integration instructions for information on In-App best practices. Furthermore, you can look at the sample application for implementation samples.

News Feed

See the iOS integration instructions for information on how to integrate the News Feed into your Xamarin iOS app. Furthermore, you can look at the sample application implementation samples.

Of all the implementation options, the quickest to implement is the Modal, which can be added by doing

ABKFeedViewControllerModalContext m = new ABKFeedViewControllerModalContext ();
this.PresentViewController (m, true, null);

in your ViewController.

Analytics

Setting User IDs

See the iOS integration instructions for an in depth discussion of when to set and change a user ID.

Xamarin C#

Appboy.SharedInstance().ChangeUser("YOUR_USER_ID");

Logging Custom Events

See the iOS integration instructions for in depth discussion of event tracking best practices and interfaces.

Xamarin C#

Appboy.SharedInstance ().LogCustomEvent ("YOUR_EVENT_NAME");

Implementation Example

logCustomEvent is utilized within the AppboySampleViewController.cs within the TestApp.XamariniOS sample application.

Setting Custom Attributes

See the iOS integration instructions for in depth discussion of attribute tracking best practices and interfaces.

Xamarin C#

Appboy.SharedInstance ().User.FirstName = "YOUR_NAME";

Implementation Example

You can see user properties being set in the sample application’s UserPropertyButtonHandler method inside AppboySampleViewController.cs.

Logging Purchses

See the iOS integration instructions for in depth discussion of revenue tracking best practices and interfaces.

Xamarin C#

Appboy.SharedInstance ().LogPurchase ("myProduct", "USD", new NSDecimalNumber("10"));

Implementation Example

You can see user properties being set in the sample application’s EventsAndPurchasesButtonHandler method inside AppboySampleViewController.cs.

Customer Feedback

The Customer Feedback module has been deprecated and is not available to new integrations.

See the iOS integration instructions for information on how to integrate the feedback form into your Xamarin iOS app. Furthermore, you can look at the sample application for implementation samples.