Giter Site home page Giter Site logo

saramgsilva / notificationhubs Goto Github PK

View Code? Open in Web Editor NEW
25.0 9.0 15.0 21.18 MB

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

Home Page: http://saramgsilva.github.io/NotificationHubs/

License: MIT License

C# 43.76% ASP 0.02% Groff 3.04% Visual Basic 11.60% Java 37.56% Objective-C 1.44% CSS 0.24% HTML 0.47% JavaScript 1.87%

notificationhubs's Introduction

Azure Notification Hubs Sample

This sample is related to the article from MSDN Magazine (April 2015):

Azure Notification Hubs: Best Pratices Managing Devices

◻️ Table of contents

◻️ 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:

  • The two main ways to manage devices in Azure Notification Hubs, using the Registration Model:

    • Case 1 - Devices register directly in Azure Notification Hubs
    • Case 2 - Devices register in Azure Notification Hubs through backend
  • Azure Mobile Services;

◻️ Sample Status

  • Key: ✅ = Supported, ❌ = Not Supported, 🔧 = In development
Windows Applications - Using XAML / CSharp
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)
Windows Applications - Using XAML / Visual Basic
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)
Xamarin Applications
Platform Azure Mobile Services Registration Model (Case1) Registration Model (Case2)
Xamarin Android
Xamarin IOS

Others

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

⚠️ 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.

◻️ Requirements

  • Create the Azure Notification Hubs in Azure Portal (Azure Mobile Service create it by default)
  • Create the required data, in Push Notification Service (WNS, GCM, APNs...), to support push notification for each Platform
  • Configure the Azure Notification Hub, in Azure Portal, with the data from Push Notification Services (WNS, GCM, APNs...)
  • Add connection string and hub name from the Azure Notification Hub created (in the sample it is defined in Contants.cs file

⚠️ Change required before run each sample

The Contants.cs file should be defined, which:

  • SenderID: define the ProjectID used in Xamarin Android and Android projects to request a registrationId from Google Cloud Messaging (GCM)

  • HubName: define the Notification Hub's name created in Azure Portal

  • ConnectionString: define the Notification Hub's connection string for the client applications connect with Notification Hub.

  • BackEndConnectionString: define the Notification Hub's connection string for the backend connect with Notification Hub.

  • AMSEndpoint: define the url from the Azure Mobile Services, used by the client application when create the object to connect with Azure Mobile Services

  • AMSKey: define the admin key used by the client application when create the object to connect with Azure Mobile Services.

◻️ The Source Code

The sample has the following project's struture:

  • Shared
  • BackEnd
  • Windows
    • CSharp
      • Windows Phone 8.1 (WinRT)
      • Windows Store Apps (WinRT)
      • Windows Phone 8.1 (SL)
    • Visual Basic
      • Windows Phone 8.1 (WinRT)
      • Windows Store Apps (WinRT)
      • Windows Phone 8.1 (SL)
  • Xamarin
    • Xamarin.Android
    • Xamarin.IOS

◻️ 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.

◻️ Resources

◻️ Common Issues

The following list provide some common issues I found when I did the sample or even when help others developers.

In General

  • The connection string from Notification Hubs is wrong;
  • The xml/json that define the template are not well defined;
  • When debug the notification is not using the correct tag or forget to use the tag;
  • Is missing the configurations in Azure Portal for each application;
  • In Azure Mobile Services developers uses the Notification Hubs API to manage devices and it is not necessary because Azure Mobile Service give us it out-of-box;
  • When developers implement the registration in devices do not use the debug feature to verify if the devices was registered correctly;
  • Developers implements the Case 1 when they want to implement the Case 2 and mixes the two cases;

In Windows (WinRT) apps:

  • In manifest should be defined the Toast capable;
  • In manifest should be defined the Internet capability;
  • Associate with store;

In Windows Phone (SL) apps:

  • In manifest should be defined Internet capability, Toast capable and the ID_CAP_PushNotification
  • Should be handled the notification when the app is running

In Android apps:

  • The Project Id is wrong;
  • The GCM component is missing;
  • In debug mode, after stop the debug be aware that is need to run again the app to receive the notifications;
  • The manifest file must have the package's name starting with lower case;
  • The key used in the payload is not the same in the application;

In iOS apps:

  • To enable push notification is required the certificates that enable it. The process is not simple to create it and it is easy to do a mess between steps;
  • Developers should confirm which version of the certificate is on Azure Portal and it is used by application. This means if in Azure Portal has the production certificate the application must have the production certificate;
  • The plist must have the push notification checked and the bundle must match with the bounded created;

◻️ Tips

Azure Notification Hubs API

⚠️ It was published a new nuget: Microsoft Azure Notification Hubs

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

◻️ Contributors

◻️ Contribute

Everbody is welcome to contribute.

Twitter hashtag : #notificationhubs

◻️ License

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

notificationhubs's People

Contributors

rosanarufer avatar saramgsilva avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

notificationhubs's Issues

Case 2 - Xamarin Android gcm client help

Been trying to implement parts of your case 2 project. But I get stuck at the GcmClient.Register. For some reason it never calls the OnRegistered function. I set the required package name in the broadcast receiver and I pass along a valid SenderID. Still no luck. If you have some time to help me some I'd really appreciate it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.