Sample to help developers to implement Push Notification, through Azure Notification Hubs, in mobile applications.
What is this?
Requirements
Sample Status
The Solution
Screenshots
Resources
Common Issues
Tips
Build the project
The sample provided has the goal to help developers add Push Notifications to their applications, through Azure Notification Hubs and this sample supports:
The two main ways to manage devices in Azure Notification Hubs, using the Registration Model:
Azure Mobile Services;
Platform | Azure Mobile Services | Registration Model (Case1) | Registration Model (Case2) |
---|---|---|---|
Windows Store 8.1 (WinRT) | |||
Windows Phone 8.1 (WinRT) | |||
Windows Phone 8.1 (SL) |
Platform | Azure Mobile Services | Registration Model (Case1) | Registration Model (Case2) |
---|---|---|---|
Windows Store 8.1 (WinRT) | |||
Windows Phone 8.1 (WinRT) | |||
Windows Phone 8.1 (SL) |
Platform | Azure Mobile Services | Registration Model (Case1) | Registration Model (Case2) |
---|---|---|---|
Xamarin Android | |||
Xamarin IOS |
Platform | Azure Mobile Services | Registration Model (Case1) | Registration Model (Case2) |
---|---|---|---|
Android Native | |||
IOS Native | |||
Cordova |
Notes:
The Windows Phone 8.0 implementation is similar to Windows Phone 8.1 SL implementation, this way it will not be provided.
For Cordova apps, see the article MSDN Magazine - Push Notifications to Cordova Apps with Microsoft Azure by Glenn Gailey.
Change required before run each sample
The Contants.cs file should be defined, which:
The sample has the following project's struture:
To develop on this project, just clone the project to your computer, package restore is enable so build the solution first, if you get any errors try to build again and if necessary close the solution and open again to load the references.
The following list provide some common issues I found when I did the sample or even when help others developers.
In General
In Windows (WinRT) apps:
In Windows Phone (SL) apps:
In Android apps:
In iOS apps:
Used in Case 2 sample
Platform | Azure Notification Hubs API |
---|---|
Windows Store 8.1 (WinRT) | WindowsAzure.Messaging.Managed |
Windows Phone 8.1 (WinRT) | WindowsAzure.Messaging.Managed |
Windows Phone 8.1 (SL) | WindowsAzure.Messaging.Managed |
Xamarin Android | Azure Messaging |
Xamarin IOS | Azure Messaging |
Used in Azure Mobile Service sample
Platform | Push Notification Service |
---|---|
Windows Store 8.1 (WinRT) | Windows Push Notification Services (WNS) |
Windows Phone 8.1 (WinRT) | Windows Push Notification Services (WNS) |
Windows Phone 8.1 (SL) | Microsoft Push Notification Service (MPNS) |
Windows Phone 8.0 (SL) | Microsoft Push Notification Service (MPNS) |
Android | Google Cloud Service (GCM) |
IOS | Apple Push Notification Service (APNs) |
Windows Phone 8.1 and Windows Store apps (WinRT)
var payload = new XElement("toast",
new XElement("visual",
new XElement("binding",
new XAttribute("template", "ToastText01"),
new XElement("text",
new XAttribute("id", "1"), message)))).ToString(SaveOptions.DisableFormatting);
Windows Phone 8.1 SL
var mpnsPushMessage = new MpnsPushMessage(toast);
XNamespace wp = "WPNotification";
XDocument doc = new XDocument(new XDeclaration("1.0", "utf-8", null),
new XElement(wp + "Notification", new XAttribute(XNamespace.Xmlns + "wp", "WPNotification"),
new XElement(wp + "Toast",
new XElement(wp + "Text1",
"Notification Hubs Sample"),
new XElement(wp + "Text2", message))));
var xmlPayload = string.Concat(doc.Declaration, doc.ToString(SaveOptions.DisableFormatting));
IOS
var alert =new JObject(
new JProperty("aps", new JObject(new JProperty("alert", notificationText))),
new JProperty("inAppMessage", notificationText))
.ToString(Newtonsoft.Json.Formatting.None);
Android
var payload = new JObject(
new JProperty("data", new JObject(new JProperty("message", notificationText))))
.ToString(Newtonsoft.Json.Formatting.None);
If you are using simulator and do the deploy for install the app or debug it, you can receive Push Notification while the app run, but if you stop and try to send another Push Notification the simulator will not receive it, you should run again the app without VS to get the push notification
Everbody is welcome to contribute.
Twitter hashtag : #notificationhubs
MIT License (MIT), read more about it in the LICENSE file.