How to use Azure Notification Hubs to send push notifications.
This slide deck was part of the TVUG May 2015 presentation (http://tvug.net/post/may-meeting-mobile-app-push-notifications-using-azure)
13. Platform ID Token used by platform notification services to target the device
Template The message template with placeholder fields
Tags Comma separated list of string values
14. Type Format Notes
Platform APNS Broadcast to just iOS devices
User GUID Specific to the user
Topic GUID User could subscribe to a topic likeYankees Baseball
MyApp String Broadcast to all
31. public partial class AppDelegate : FormsApplicationDelegate, ILoginManager
{
private string Serial;
private string LoginId;
/*
* APNS uses a sandbox certificate for debugging and a production certificate for App Store and Ad Hoc release
* Each notification hub can use the public key for either the sandbox or the production cert. We use the DEBUG
* compile time contant to specify which hub to use
*/
#if DEBUG
const string HUB_NAME = "mystopsandbox";
const string HUB_LISTEN_SECRET = "LgOtX//jlMw/zNWmkAHZssZm/XddWUo+IamZi1v1RS4=";
#else
const string HUB_NAME = "mystopnotificationhub";
const string HUB_LISTEN_SECRET = "656Ns/udsz86M0+Cbc2pWTuhllB/KXcO0gaq1d7DxdM=";
#endif
32.
33. List<string> tags = new List<string> { Serial, "ios", "tyler", AppSettings.LoginGuid };
var n = new NSSet(tags.ToArray());
var alerts = "{"aps":{"alert":"$(message)","title":"$(title)"}}";
var expire = DateTime.Now.AddDays(90).ToString(CultureInfo.CreateSpecificCulture("en-US"));
hub.RegisterTemplateAsync(deviceToken, "alerts", alerts, expire, n, err => {
if (err != null)
Console.WriteLine("Error: " + err.Description);
else
Console.WriteLine("Success");
});
34. var alerts = "{"data":{"message":"$(message)","title":"$(title)"}}";
hub.RegisterTemplate(registrationId, "alerts", alerts, tags.ToArray());
You can do this in two ways
The app can register with your service and with the hub separately
The app can register with your service and the service can register the user/device with the hub
The push mechanism for Windows will depend on which platform you are targetting WNS for Wp 8.1 Silverlight or MPSN
This step can also be done in the your service
Additional tags can be added. Azure “ORs” them. We send a push request using a single tag.
Resinstalling the app will generate a new device id on iOS
For iOS and Windows, the OS handles bulk of the work.
There is a descendant of the Android BroadCastReceiver class that comes from the Azure Messaging component. BroadCastReceiver is the base class for apps and services to receive broadcast messages. The class provided with this component is designed to receive
This BroadCastReceiver is registered with the OS to receive GCM messages and to be woken up briefly if the app is not running.
If the app is in the foreground, it can display a Toast message and invokes an Android service that is part of app. That service requests a notification message from the OS.
If the app was woken up by the OS, it just calls the service for the notification.
To be woken up, the app must be compiled for release.
Refresh the profiles in Xcode and then restart Xamarin