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:
- Connecting your app to the platform
- Getting push certs or API keys
A full Xamarin integration guide is given for Android and iOS below. Note if you are using Xamarin.Forms, you must complete the integration for each platform as described on this page and then you must also follow the steps outlined here.
Android
First thing we need to do is get a Google-Services.json file associated with our project.
Go to the firebase console by clicking here.
If you currently have no projects created, create one.
Now navigate to the project settings.
Next step is to add your app to the Firebase project:
Now download the Google-services.json associated with that app as we will need it later.
- 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
- In your IDE, add two additional Packages to the project to satisfy the underlying dependencies of our SDK.
- Google Play Services - Location (latest stable NuGet package currently 71.1600.0)
- Xamarin.Firebase.Messaging (latest stable NuGet package currently 71.1740.0)
- Edit the AndroidManifest.xml file to add the following elements within the manifest element:
- Edit the AndroidManifest.xml file to add the following elements within the application element
- 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:
- Pull in the xtremepush library
using IE.Imobile.Extremepush;
using IE.Imobile.Extremepush.Api.Model;
- You may require some of the following packages in the same file, if not imported already
using Android.App;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;
using System;
using System.Collections.Generic;
- Now we need to add the google-services.json to our project
- Override the Application onCreate function to initialise the xtremepush SDK (swapping in your real app key and GCM project number into the code below). This example also shows how you can register a callback for message response events, and register a callback when the inbox badge is updated.
- 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
- In the Source view of the Info.plist file:
- XtremePushApplicationKey -> your app key from the General Settings page on the dashboard
- NSBluetoothPeripheralUsageDescription. It is a required usage description you have to add to your app if it includes CoreBluetooth (even if core bluetooth is not actively used). The xtremepush iOS SDK currently requires you to do that. See docs here for more information.
- If using location/beacon functionality in your app, make sure that you have entries for NSLocationAlwaysUsageDescription, NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationWhenInUseUsageDescription in the same file
- Edit the AppDelegate.cs file and add the following lines inside the FinishedLaunching() function:
- Add the following function to the AppDelegate.cs file if you want to handle inbox badge updated events:
- Edit the AppDelegate.cs file and add the following callbacks to our SDK
- If you need to associate an Apple ID with your IDE, do this now in the IDE preferences:
- Edit the Entitlements.plist file to enable push notifications
- If you are not using Xamarin.forms and 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");
iOS 10 foreground notification handling
If you want to receive notifications when your app is in the foreground. This is possible on iOS10 and above by calling the following method inside FinishedLaunching():
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
Updating to Firebase Release
Please make the following changes in the AndroidManifest.xml file:
Delete the following three elements if present:
And then add the following elements back in:
Comments
0 comments
Article is closed for comments.