With the  Aerogear Unified Push Server (UPS) it is possible to send Push-Notifications to various Device-Families. It is possible to register devices with iOS, Android and Windows Operating Systems.

Unfortunately there is no Guide for Xamarin. But there is a module for c# from which you can adapt a lot of source code to make the registration with UPs possible.

Device registration at the Push-Notification Service (APNS, GCM, WNS)

First you need to register the device at the Push-Notification Service. Therefore you can follow the instructions from Xamarin or Aerogear:

APNS (Apple Push Notification Service):
https://developer.xamarin.com/guides/cross-platform/application_fundamentals/notifications/ios/remote_notifications_in_ios/

GCM (Goolge Cloud Messaging), inkl. Kapitel „Register with GCM“:
https://developer.xamarin.com/guides/cross-platform/application_fundamentals/notifications/android/google-cloud-messaging/

WNS (Windows Push Notification Service):

We haven’t tests WNS yet. but it should be possible to follow the instructions from Aerogear for C#:
https://aerogear.org/docs/unifiedpush/aerogear-push-windows/guides/#windows-setup

Also the Aerogar module for Windows (C#) should work fine. It can be installed easily via NuGet:
https://aerogear.org/windows/

Here is an example how to register with APNS.
In AppDelegate.cs.
Connect to APNS in FinishedLaunching:

Receive Answer (DeviceToken) from APNS and save the DeviceToken.

 

RegisterUPS() will then register the Device with UPS.

If the registration succeeded, APNS will return a DeviceToken which we need to send to UPS for registration.

Registration with UPS

As mentioned we adopted code from the Aerogear Windows module. In particular we used the UPSHttpClient, you can find the original code here:
https://github.com/aerogear/aerogear-windows-push/blob/master/aerogear-windows-push/UPSHttpClient.cs

We created a new C# class named UPSRegister.

Source code of UPSRegister:

This class should be self explaining. The most im portend thing we added is the possibility to use a self signed SSL certificate on our server.

The function Validator validates that the connection is trustworthy. It is used in row 34:

Without this addition the connection will be rejected and probably without an error message. If you have bought a valid certificate you don’t need this addition.

Now we can instantiate this class and start the registration. We can do this in AppDelegate.cs for iOS or RegistrationIntentService.cs (see GCM Guide) for Android. Then we have to implement RegisterUPS().

RegisterUPS sourcecode:

If you are implementing for Android RegisterUPS is called in SendRegistrationToAppServer (string token).

You have to change the placeholders in  rows 4-6 with the information you get in Aerogear in the variant for your OS.

If everything went fine, you can now register your device with Aerogear and start sending push-notifications.

Receiving Push-Notifications

You can follow the instructions in the corresponding guides für Xamerin (iOS, Android) and Aerogear (Windows) on how to implement receiving push-notifications.

Example for iOS in AppDelegate.cs:

ProcessNotifocation can be implemented in different ways.

Our example:

The message sent is located in the NSDictionary options. Under the key als is another NSDictionary that contains another  NSDictionary with the key alert. The message is located in this dictionary under the key body.

This message can now be processed as you wish.  In our example we create an Alert dialog to display it.