Xamarin

The Urban Airship Xamarin component provides full bindings to the Urban Airship SDK for use in Xamarin Studio. With this component, Xamarin developers can target both iOS and Android devices with access to the full scope of the Urban Airship SDK, all while remaining in the C#/.NET ecosystem.

To see sample code demonstrating the Urban Airship features discussed in this guide, check out the samples included in the component or Xamarin Samples on GitHub.

This document will cover app setup and the component installation process, as well as basic integration steps for iOS and Android.

Setup

Before you begin, set up Push and any other Urban Airship features for iOS and Android. The Xamarin bindings, like the SDKs that they wrap, are platform-specific, so this would be a good time to familiarize yourself with the SDK APIs and features for each platform you wish to target.

Installation

Installing the Urban Airship component is a quick and easy process, seamlessly integrated into Xamarin Studio. In the Solution Explorer, double-click the “Components” folder under your app’s project. This will bring up a screen with a button inviting you to “Get More Components”. Click this button to bring up a window for the Xamarin Component Store, and search for “Urban Airship SDK”. Navigate to the component’s details page, and click the “Install” button.

Xamarin Studio will automatically download and configure all DLLs and package dependencies. Once the installation is complete, you can move on to the integration steps for your target platform.

iOS Integration

  1. In the Application’s delegate, call TakeOff in FinishedLaunching:

    [Register ("AppDelegate")]
    public class AppDelegate : UIApplicationDelegate
    {
       public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
       {
          UAirship.TakeOff ();
          // Configure airship here
          return true;
       }
    }
    

    Note

    Note that if the TakeOff process fails due to improper or missing configuration, the shared UAirship instance will be null. The Urban Airship SDK always logs implementation errors at high visibility.

  2. Provide AirshipConfig.plist file with the application’s configuration:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
       <dict>
          <key>detectProvisioningMode</key>
          <true/>
          <key>developmentAppKey</key>
          <string>Your Development App Key</string>
          <key>developmentAppSecret</key>
          <string>Your Development App Secret</string>
          <key>productionAppKey</key>
          <string>Your Production App Key</string>
          <key>productionAppSecret</key>
          <string>Your Production App Secret</string>
       </dict>
    </plist>
    

    In order for this file to be visible to the SDK during TakeOff, be sure that its BuildAction is set to “Bundle Resource” in your app project.

  3. Enable user notifications:

    UAirship.Push.UserPushNotificationsEnabled = true;
    

Android Integration

  1. Create a class that extends Application and call TakeOff in OnCreate:

    [Application]
    public class MainApp : Application
    {
       public MainApp(IntPtr handle, JniHandleOwnership ownerShip) : base(handle, ownerShip)
       {
       }
    
       public override void OnCreate()
       {
          base.OnCreate();
    
          // Call takeOff
          UAirship.TakeOff(this, (UAirship airship) => {
             // Configure airship here
          });
       }
    }
    
  2. Provide airshipconfig.properties file in the Assets directory with the application’s configuration:

    developmentAppKey = Your Development App Key
    developmentAppSecret = Your Development App Secret
    
    productionAppKey = Your Production App Key
    productionAppSecret = Your Production Secret
    
    # Toggles between the development and production app credentials
    # Before submitting your application to an app store set to true
    inProduction = false
    
    # LogLevel is "VERBOSE", "DEBUG", "INFO", "WARN", "ERROR" or "ASSERT"
    developmentLogLevel = DEBUG
    productionLogLevel = ERROR
    
  3. Enable user notifications:

    UAirship.Shared().PushManager.UserNotificationsEnabled = true;
    

Platform Documentation