Getting Started with Xamarin

Introduction

The Neumob Xamarin plugin implements support for using Neumob, allowing you to accelerate network requests in your Xamarin application.

Installation

To integrate the plugin, download Neumob from the Xamarin component store. Once you’ve downloaded the component, add the NeumobIOS.dll and/or the NeumobAndroid.dll file(s) to your respective iOS and/or Android projects as References.

Neumob iOS

In your AppDelegate.cs:

using NeumobIOS;

public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
    // By default, Neumob logs messages that are useful to verify
    // Neumob initialization. To disable or tune what log messages
    // are printed use the LogLevel API.
    //
    // NMLogLevel.None    - Turn off all Neumob log messages
    // NMLogLevel.Error   - Only print error messages
    // NMLogLevel.Warning - Only print warning and error messages
    // NMLogLevel.Detail  - (Default) Print all messages
    Neumob.LogLevel = (int) NMLogLevel.None;

    //Initialize Neumob with your client key from portal.neumob.com
    Neumob.Initialize("YOU CLIENT KEY", completionHandler);
    return true;
}

// The completionHandler is executed when Neumob is finished
// initialization. It is not executed on the main thread.
public void completionHandler()
{
    // `Initialized` returns a boolean indicating Neumob is enabled
    // and ready to accelerate your network requests.
    bool neumobInitialized = Neumob.Initialized;

    // `Accelerated` returns a boolean indicating whether Neumob is
    // currently accelerating your requests.
    bool neumobAccelerated = Neumob.Accelerated;

    // You may configure whether or not Neumob is accelerated by
    // adjusting the passthrough parameter on the portal. If you plan
    // to A / B test accelerated vs unaccelerated Neumob sessions, we
    // recommend using the `Accelerated` API in the completionHandler.

    // ex. Analytics.LogCustomDimension(Dimension.Accelerated, neumobAccelerated);
}

At this time the Neumob Xamarin iOS SDK supports NSUrlSession, NSUrlConnection, UIWebView, and ModernHttpClient.

Neumob Android

In your main activity class:

using NeumobAndroid;

protected override void OnCreate (Bundle bundle)
{
    // By default, Neumob logs messages that are useful to verify
    // Neumob initialization. To disable or tune what log messages
    // are printed use the LogLevel API.
    //
    // Neumob.LOG_NONE    - Turn off all Neumob log messages
    // Neumob.LOG_ERROR   - Only print error messages
    // Neumob.LOG_WARNING - Only print warning and error messages
    // Neumob.LOG_DETAIL  - (Default) Print all messages
    Neumob.SetLogLevel(Neumob.LOG_NONE);

    //Initialize Neumob with your client key from portal.neumob.com
    Neumob.Initialize(ApplicationContext, "YOUR CLIENT KEY", completionHandler);
}

// The completionHandler is executed when Neumob is finished
// initialization. It is not executed on the main thread. To write
// the appropriate delegate, you'll need to pass in a function
// returning void with 2 boolean parameters.
//
// @param initialized - boolean indicating Neumob is enabled and ready
// @param accelerated - boolean indicating whether Neumob is accelerating your requests
public void completionHandler(bool initialized, bool accelerated)
{
    // You may configure whether or not Neumob is accelerated by
    // adjusting the passthrough parameter on the portal. If you plan
    // to A / B test accelerated vs unaccelerated Neumob sessions, we
    // recommend using the `Accelerated` API in the completionHandler.

    // ex. Analytics.LogCustomDimension(Dimension.Accelerated, accelerated);
}

At this time the Neumob Xamarin Android SDK supports WebClient, HttpWebRequest, and Java.Net.HttpURLConnection.