Initial SDK Setup

Installing the Appboy SDK will provide you with basic analytics functionality as well as a working in-app slideup message 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 Appboy SDK binding.

The first 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 Appboy iOS SDK. Please make sure “AppboyPlatformXamariniOSBinding” is showing in your project’s “Reference” folder.

Project Reference

The second integration method involves getting the Appboy SDK Bindings component from the Xamarin Component store. In your application, if you right click the Components folder and click Get More Components you will be taken to the component store. Search for ‘Appboy’ and install the component into your project.

Component Reference

Note: We link SDWebImage with our SDK inside of our binding project. If you need a different version of SDWebImage in your application and it is conflicting with our binding, you can manually update the libSDWebImage.a file in our binding project.

Step 2: Update your App Delegate

Within your AppDelegate.cs file, add the following snippet within your FinishedLaunching method: Note: Be sure to update YOUR-API-KEY with the correct value from your App Settings page.

 Appboy.StartWithApiKey ("YOUR-API-KEY", UIApplication.SharedApplication, options);

Implementation Example

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

Optional: Add the Appboy bundle

If you want to use Appboy UI features (e.g. Slideup, News Feed, Feedback), you’ll need to add the Appboy bundle to your application. To do this, copy the folder from either the TestApplication in our binding repository, or, from the ios sdk (preferably checking out from the release that matches the static library in our binding to avoid version mismatch issues).

SDK Integration Complete

Appboy 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 Appboy features.

Note: Out 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 Appboy. Please contact your Customer Success manager if you want to use these features in Xamarin.

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);

Note: 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, Appboy will display a badge when a customer has unread notifications. By default, this number is 1. Appboy will only clear the badge count when the app is opened directly from an Appboy 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 ABKSlideupControllerDelegate method bool OnSlideupReceived (ABKSlideup slideup); and reply true. That will make sure Appboy 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.

Social Data Tracking

In iOS, Appboy will automatically collect social network information about your users if your users have granted access. If your app does not already prompt for Facebook or Twitter access, you can use the methods below to prompt the user for access.

Appboy.SharedInstance ().PromptUserForAccessToSocialNetwork (ABKSocialNetwork.Facebook);
// or
Appboy.SharedInstance ().PromptUserForAccessToSocialNetwork (ABKSocialNetwork.Twitter);
  • ABKSocialNetwork.Twitter
    • This only works for iOS5 and higher
    • In legacy versions of iOS this method is a no-op
  • ABKSocialNetwork.Facebook
    • This requires your Facebook App ID, which you enter in your app’s plist under the key FacebookAppID
    • You must have configured a Facebook app with your bundle ID. See Facebook’s documentation for more details on creating an app.
    • Calls to this method without a defined FacebookAppID will NSLog an error and do nothing

Recording Social Network Shares

Appboy lets you segment users based upon whether or not they have shared on social networks. To record social network shares, add this method after a successful share action in your app:

Appboy.SharedInstance ().LogSocialShare (ABKSocialNetwork.Facebook);
// or
Appboy.SharedInstance ().LogSocialShare (ABKSocialNetwork.Twitter);