Xamarin

With the xtremepush bindings for Xamarin, you can add xtremepush to both iOS and Android apps built with Xamarin.

Platform Specific Information

Xtremepush supports push notifications for iOS devices via Apples's Push Notification Service (APNs for short) and push notifications for Android devices via Google’s GCM/FCM (Google/Firebase Cloud Messaging for Android) service. This page contains Xamarin specific instructions but you will need to connect your iOS and Android app to the platform separately.

N.B. To integrate successfully you will need to have your xtremepush App Key, APNS certs for iOS and, Google project number and GCM API key for Android. These are used to connect your app to the platform and the Apple and Google push services. You will find links to documentation on connecting to the platform below:

A full Xamarin integration guide is given for Android and iOS below. 

Android

  • Download the latest Xamarin bindings DLL file from the Mobile Frameworks page
  • In your IDE (Visual Studio or Xamarin Studio), add a reference in your app project to the DLL file
    • Edit References -> .Net Assembly -> Browse... -> Select the DLL

Screen_Shot_2017-04-10_at_19.13.02.png

  • In your IDE, add two additional components to the project to satisfy the underlying dependencies of our SDK. 
    • Google Play Services - Location
    • Google Play Services - Cloud Messaging (GCM)
  • Edit the AndroidManifest.xml file to add the following elements within the manifest element:
<!-- REQUIRED for xtremepush -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />

<!-- OPTIONAL xtremepush settings-->
<!-- REQUIRED PERMISSIONS for GCM -->
<!-- GCM requires a Google account. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- This app has permission to register with GCM and receive message -->
<permission android:name=".permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name=".permission.C2D_MESSAGE" />
<!-- The two elements above ensure that only this application can receive the messages and registration result -->

<!-- REQUIRED FOR Geo-Location and iBeacon Scanning-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<!-- REQUIRED IF you support iBeacon and your app must support devices that don't support BLE -->
<uses-feature
    android:name="android.hardware.bluetooth_le"
    android:required="false" />
<uses-permission android:name="android.permission.BLUETOOTH" android:required="false"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:required="false"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
  • Edit the AndroidManifest.xml file to add the following elements within the application element
<!-- Required For Campaign Functionality -->
<service android:name="ie.imobile.extremepush.GCMIntentService" />
<activity
    android:name="ie.imobile.extremepush.ui.OnclickPushActivity"
    android:exported="false"
    android:noHistory="true" />
<service android:name="ie.imobile.extremepush.NotificationOnClickHandlerService" />
<activity
    android:name="ie.imobile.extremepush.ui.WebViewActivity"
    android:exported="false" />

<!-- Required For Inbox Functionality -->
<activity
    android:name="ie.imobile.extremepush.ui.InboxActivity"
    android:label="@string/title_activity_inbox"
    android:theme="@style/Theme.Transparent"
    android:configChanges="orientation|screenSize" />

<!-- Required For GCM, Location AND Beacon -->
<receiver
    android:name="ie.imobile.extremepush.receivers.GCMReceiver"
    android:permission="com.google.android.c2dm.permission.SEND" >
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
        <action android:name="ie.imobile.extremepush.BEACON_SERVICE_STARTED" />
        <category android:name="." />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
        <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
    </intent-filter>
</receiver>

<!-- Required For Location Services -->
<service android:name="ie.imobile.extremepush.location.GeoLocationService" />
<service
    android:name="ie.imobile.extremepush.location.ProxymityAlertReceiver"/>
<activity
    android:name="ie.imobile.extremepush.ui.LocationDialogActivity"
    android:label="Locations are not available"
    android:theme="@android:style/Theme.Dialog"
    android:exported="false" />

<!-- Required For iBeacon -->
<service android:name="ie.imobile.extremepush.beacons.BeaconLocationService" />
<receiver android:name="org.altbeacon.beacon.startup.StartupBroadcastReceiver">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED"/>
        <action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
        <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
    </intent-filter>
</receiver>
<service android:enabled="true"
    android:exported="false"
    android:isolatedProcess="false"
    android:label="beacon"
    android:name="org.altbeacon.beacon.service.BeaconService" />
<service android:name="org.altbeacon.beacon.BeaconIntentProcessor"
    android:enabled="true"
    android:exported="false" />
  • Edit the AndroidManifest.xml file to make sure there is an icon set within the application element. This is required for the correct generation of notifications
<application android:icon="@mipmap/icon" android:label="@string/app_name">
  • In the root C# file of your project:
    • using IE.Imobile.Extremepush;
    • Pull in the xtremepush library
    • The following two packages are also required in the same file, if not imported already
      • using System;
      • using Android.Runtime;
    • Override the Application onCreate function to initialise the xtremepush SDK (swapping in your real app key and GCM project number into the code below)
[Application]
public class MainApp : Application
{
    public MainApp(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
    {
    }

    public override void OnCreate()
    {
        base.OnCreate();
        String XPUSH_APP_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        String GOOGLE_PROJECT_NUMBER = "XXXXXXXXXXXX";
        new PushConnector.Builder(XPUSH_APP_KEY, GOOGLE_PROJECT_NUMBER)
                         .Create(this);
    }
}
  •  If you want to send tags or events to our platform elsewhere in your app, this can be achieved with the following function calls:
    • PushConnector.MPushConnector.HitTag("TestTag");
    • PushConnector.MPushConnector.HitEvent("TestEvent");

iOS

  • Download the latest Xamarin bindings DLL file from the Mobile Frameworks page
  • In your IDE (Visual Studio or Xamarin Studio), add a reference in your app project to the DLL file
    • Edit References -> .Net Assembly -> Browse... -> Select the DLL

Screen_Shot_2017-04-20_at_20.45.31.png

  • In the Source view of the Info.plist file:
    • XtremePushApplicationKey -> your app key from the General Settings page on the dashboard
    • Add the following key-value pair of strings:
    • If using location/beacon functionality in your app, make sure that you have an entry for NSLocationAlwaysUsageDescription in the same file

Screen_Shot_2017-04-21_at_15.16.58.png

  • Edit the AppDelegate.cs file and add the following lines inside the FinishedLaunching() function:
// Setup xtremepush
int types;
if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) {
    types = (int) (UIUserNotificationType.Badge | UIUserNotificationType.Alert | UIUserNotificationType.Sound);
} else {
    types = (int) (UIRemoteNotificationType.Alert | UIRemoteNotificationType.Sound | UIRemoteNotificationType.Badge);
}
XPush.XPush.RegisterForRemoteNotificationTypes(types);
XPush.XPush.SetSandboxModeEnabled(true); //Required if doing a debug/dev build of your app
XPush.XPush.SetLocationEnabled(true); // Required for location or beacon functionality
XPush.XPush.ApplicationDidFinishLaunchingWithOptions((launchOptions != null) ? launchOptions : new NSDictionary());
  • Edit the AppDelegate.cs file and add the following callbacks to our SDK
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
    XPush.XPush.ApplicationDidRegisterForRemoteNotificationsWithDeviceToken(deviceToken);
}

public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
{
    XPush.XPush.ApplicationDidFailToRegisterForRemoteNotificationsWithError(error);
}

public override void ReceivedLocalNotification(UIApplication application, UILocalNotification notification)
{
    XPush.XPush.ApplicationDidReceiveLocalNotification(notification);
}

public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
{
    XPush.XPush.ApplicationDidReceiveRemoteNotification(userInfo);
}
  • If you need to associate an Apple ID with your IDE, do this now in the IDE preferences:

Screen_Shot_2017-04-21_at_13.34.56.png

  • Edit the Entitlements.plist file to enable push notifications

Screen_Shot_2017-04-20_at_20.57.14.png

  • If you want to send tags or events to our platform elsewhere in your app, this can be achieved with the following function calls:
    • XPush.XPush.HitTag("TestTag");
    • XPush.XPush.HitEvent("TestEvent");

Troubleshooting

  • Build error like the following: "Could not AOT the assembly ... xpios.dll"
    • Switch off Project Options -> Build -> iOS Build -> Enable incremental builds
    • Rebuild the project again (should now succeed)
    • Should be possible to Enable incremental builds again after this point
Have more questions? Submit a request

0 Comments

Article is closed for comments.