Azure Notification Hubs Sample

Sample to help developers to implement Push Notification, through Azure Notification Hubs, in mobile applications.

Star Fork

What is this?
Requirements
Sample Status
The Solution
Screenshots
Resources
Common Issues
Tips
Build the project

Contributors

This sample is related to the article from MSDN Magazine (April 2015)
Azure Notification Hubs: Best Pratices Managing Devices


:white_medium_square: What is this?

The sample provided has the goal to help developers add Push Notifications to their applications, through Azure Notification Hubs and this sample supports:

:white_medium_square: Sample Status

Windows Applications - Using XAML / CSharp
Platform Azure Mobile Services Registration Model (Case1) Registration Model (Case2)
Windows Store 8.1 (WinRT) :white_check_mark: :white_check_mark: :white_check_mark:
Windows Phone 8.1 (WinRT) :white_check_mark: :white_check_mark: :white_check_mark:
Windows Phone 8.1 (SL) :white_check_mark: :white_check_mark: :white_check_mark:
Windows Applications - Using XAML / Visual Basic
Platform Azure Mobile Services Registration Model (Case1) Registration Model (Case2)
Windows Store 8.1 (WinRT) :white_check_mark: :white_check_mark: :white_check_mark:
Windows Phone 8.1 (WinRT) :white_check_mark: :white_check_mark: :white_check_mark:
Windows Phone 8.1 (SL) :white_check_mark: :white_check_mark: :white_check_mark:
Xamarin Applications
Platform Azure Mobile Services Registration Model (Case1) Registration Model (Case2)
Xamarin Android :white_check_mark: :white_check_mark: :white_check_mark:
Xamarin IOS :white_check_mark: :white_check_mark: :white_check_mark:

Others

Platform Azure Mobile Services Registration Model (Case1) Registration Model (Case2)
Android Native :white_check_mark: :x: :x:
IOS Native :x: :white_check_mark: :x:
Cordova :x: :x: :x:

:warning: Notes:

  1. The Windows Phone 8.0 implementation is similar to Windows Phone 8.1 SL implementation, this way it will not be provided.

  2. For Cordova apps, see the article MSDN Magazine - Push Notifications to Cordova Apps with Microsoft Azure by Glenn Gailey.

:white_medium_square: Requirements

:warning: Change required before run each sample

The Contants.cs file should be defined, which:

:white_medium_square: The Source Code

The sample has the following project's struture:

:white_medium_square: Build the projects

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.

:white_medium_square: Resources

:white_medium_square: Common Issues

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:

:white_medium_square: Tips

Azure Notification Hubs API

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

Windows Azure Mobile Services

Push Notification Service by Platform

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)

Push Notification Templates by platform

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);

Development In Xamarin.Android

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

:white_medium_square: Contributors

:white_medium_square: Contribute

Everbody is welcome to contribute.

Twitter hashtag : #notificationhubs

:white_medium_square: License

MIT License (MIT), read more about it in the LICENSE file.