Coder Social home page Coder Social logo

azure / azure-notificationhubs-samples Goto Github PK

View Code? Open in Web Editor NEW
160.0 47.0 237.0 26.06 MB

Microsoft Azure Notification Hubs Samples

License: Apache License 2.0

C# 22.68% JavaScript 18.31% HTML 3.53% PowerShell 4.52% CSS 41.19% PHP 0.95% Java 0.66% Python 1.36% TypeScript 4.05% SCSS 0.75% ASP.NET 0.01% Ruby 0.13% Objective-C 1.10% Dart 0.69% Starlark 0.07%

azure-notificationhubs-samples's Introduction

Azure Notification Hubs Samples

This repository contains sample code for Azure Notification Hubs. Click on the heading to open the selected portion of the repository. The links in the sections below point to tutorials in the Azure Notification Hubs documentation.

The sample applications for Android, iOS, and .NET were moved to the SDK repository for each target platform:

Client Applications

Samples illustrating how to use Azure Notification Hubs in a client application.

An example of using Flutter with the Azure Notification Hubs SDKs for both Apple and Android.

A simple example of how to use Azure Notification Hubs with an Apache Cordova application. The app uses the cordova-azure-notification-hubs plugin.

A simple example of how to use Azure Notification Hubs with an Ionic 3 application. The app uses the cordova-azure-notification-hubs plugin.

Push Apps

Samples illustrating how to send notifications to apps using Azure Notification Hubs.

Sample on how to send push notifications to Safari using Azure Notification Hubs and Azure Web Sites.

SDK

This is a sample for sending notifications to Notification Hubs using PHP.

This is a sample for sending notifications to Notification Hubs using Python.

azure-notificationhubs-samples's People

Contributors

chadelofson avatar dependabot[bot] avatar efimovandr avatar fsautomata avatar jwargo avatar keizie avatar kirill-pyatunin avatar kostya-zhidovinov avatar kulkarnikushal17 avatar kylekampy avatar marstr avatar mpodwysocki avatar piyushjo avatar sateeshpr avatar sethmanheim avatar smithab avatar tryjsky avatar wesmc7777 avatar ysxu 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  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  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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

azure-notificationhubs-samples's Issues

Which samples would you like to see?

As you have noticed, we have a number of samples in a number of languages. Going forward, as we modernize these samples, which languages would you like to see? Note that this is a poll and not any guarantee whether we will implement any of all of them.

Clients:

  • JavaScript via Cordova, Ionic, NativeScript, React Native
  • Android with Kotlin and Java
  • iOS with Swift and Objective-C

Servers:

  • NodeJS
  • Go
  • Rust
  • .NET Core
  • Java

Error using the Cordova Sample

I am getting an error during the build of the app using the sample for Apache Cordova.
I solved upgrading the cordova version, removing the android platform and adding again. I think will be better to updathe the solution here to avoid future issues with new users.

Do you have any plans to have a sample for Ionic 4?

Sample error:
Plugin doesn't support this project's cordova-android version. cordova-android: 6.2.3, failed version requirement: >=7.1.0 Skipping 'cordova-azure-notification-hubs' for android

Commands used:
npm install -g cordova --> upgrade Cordova
cordova platform remove android --> Remove current Android platform
cordova platform add android --> Install Android platform again witht the plugins

cordova azure push notification custom backend

I am trying to work around the following:

Azure push notification (WNS and GCM)
Custom backend (more on that bellow)
Win10 client (working fine so far)
cordova client for Android/iOS (current pain point)
As opposed to most tutorials found on Azure documentation I want to use my own node backend to trigger notifications and not an Azure Mobile Service.

I have configured Azure push notification and I can send and receive notification on a W10 client using only Notification hub connection strings such as:
Endpoint=sb://<myns>.servicebus.windows.net/;SharedAccessKeyName=<mykeyname>;SharedAccessKey=<mykey>
I can register my notification template and receive notifications on my W10 app.

I want now to do the same on a Cordova app. All the tutorials I have found so far rely on first connecting to an Azure Mobile Service and access the push service through its client.

What I am trying to do is register a custom notification template using an EndPoint=sb:// connection string so I can receive notifications on my Android device.

On my custom node backend, I use the Azure package and its createNotificationHubService method to send custom notifications.

Any pointers on how to register an Azure Notification Hub client without an Azure Mobile service backend would be greatly appreciated.

A.

Sending high priority message via GCM

I'm using Notification Hub to send noifications to my Android aplication. My question is by default what priority does the SDK use to send notifications and can this be configured. Based on what I have seen on Google's website https://developers.google.com/cloud-messaging/concept-options?hl=en I can simply add the priority as part of the payload. However I am not sure how the underlying SDK handles this and if it adds a priority by default. This is what I did. The notification is being sent with the code below but I'm wondering if the priority value has any effect.

var payload = new
{
priority="high",
data = new
{
message = new
{
model.Title,
model.Time,
model.Message,
model.NotificationId,
model.NotificationType,
model.SenderFacebookId,
model.TargetId,
model.TargetUserFacebookId
}
}
};

                var json = JsonConvert.SerializeObject(payload);
                await hub.SendGcmNativeNotificationAsync(json, Tag.UserDevice.GetStringValue() + deviceId);

How to send the push notification to the specific IOS User's

STOP: Have you discovered a problem with a sample found here, or are you looking for help getting the sample to work for you?

If you're looking for help getting a sample working for you, please ask on Stack Overflow with the tag azure-notificationhub. You'll be asking a broader community for help, potentially getting you an answer more quickly.

I Want to send the notification to Specific IOS device

So explain me how to send the push notification to the specific IOS device user

I have Tried but not getting anything from any docs

Registration issue with oreo

I am using Azure Could Messaging with andorid. It is working fine on device with android 6. When i run it on android 8, it ie giving error on following line.

NotificationHub hub = new NotificationHub(getNotificationHubName(),
getNotificationHubConnectionString(), this);
hub.register(FCM_token, tags).getRegistrationId();

it is giving following error on the code "hub.register(FCM_token, tags)":

"javax.net.ssl.SSLHandshakeException: Chain validation failed."

I iterated the code in deep to azure library. And i found that it is giving the error on exactly the following line

AndroidHttpClient.newInstance(getUserAgent()).execute(request);

Sample doesnt work in iOS version 14. Are there any alternatives ?

As the deviceRegistrationId format is changed from iOS 13 and above, the token received is in format
Push Plugin register success: {length = 32, bytes = 0x12345678 12345678 12345678 12345678 ... 12345678 1234567b }

In iOS app crashes at,

  • (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData )deviceToken {
    if (self.callbackId == nil) {
    NSLog(@"Unexpected call to didRegisterForRemoteNotificationsWithDeviceToken, ignoring: %@", deviceToken);
    return;
    }
    NSLog(@"Push Plugin register success: %@", deviceToken);
    SBNotificationHub
    hub = [[SBNotificationHub alloc] initWithConnectionString:self.connectionString
    notificationHubPath:self.notificationHubPath];
    [hub registerNativeWithDeviceToken:deviceToken tags:nil completion:^(NSError error) {*

Any one was able to resolve this ?

Push Sharp on actual iOS device

Works fine on iOS simulator.

Throws the following message when building for device:
Error MT2002: Failed to resolve "System.Reflection.Emit.ILGenerator" reference from "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" (MT2002)

Is it a problem with dynamic code generation which is forbidden by Apple?

Update to SendNHRegistraion to use Tags

Hi,

Not sure how to do this pull / push request stuff ! but a suggestion...

I have updated the method here to accept a taglist as per the other implementations..

private static void SendNHRegistrationRequest(string pushChannel, string taglist) { Payload = @" {TagList} {WindowsPushChannel} ";
        Payload = Payload.Replace("{WindowsPushChannel}", pushChannel);
        Payload = Payload.Replace("{TagList}", taglist);
        var uri = new Uri(Endpoint + HubName + "/registrations/" + ApiVersion);
        var sendRequest = WebRequest.CreateHttp(uri);
        sendRequest.Method = "POST";
        sendRequest.ContentType = ContentType;
        sendRequest.Headers[AuthHeader] = GenerateSaSToken(uri);
        sendRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), sendRequest);
    }

WP8.1 Silverlight Unauthorized

I'm getting Unauthorized when trying to use the PushToSLPhoneApp example. I've put my Identity tag at Package.appxmanifest:
<Identity Name="...." Publisher="...." Version="...." />

And I've also set my notificationHubName and connectionString at MainPage.cs/RegisterToReceiveNotifications.

At Azure Portal, I've set my Package SID and Security Key at WNS Settings.

Update needed on notificationhubs-rest-php Readme

All of the examples use

$hub->sendNotification($notification);

there is not a method that takes in just one argument!

$hub->sendNotification($notification,null); however does work or an array or a string (the tag)

Python SDK doesn't support iOS silent or scheduled pushes

I'm interested in making a pull request to add support - what guidelines should I be following, and are there any considerations that should be taken into account? I am implementing this primarily for Python 2.7, so I have also updated the sample to work within that context.

The Token obtained from the Token Provider is wrong

Hi,

I am able to send toast notification to my Android app from Azure portal(using Debug) but getting below error when i tried sending toast notification using python script mentioned in this post.

C:\Users\satish.gunjal\Google Drive\My Projects\Home Automation\Source Code\Python-RaspberryPi>py NotificationHub.py

--- REQUEST ---

URI: https://cavenotificationhub-ns.servicebus.windows.net/cavenotificationhub/messages?api-version=2013-10&test

Headers: {

"Authorization": "SharedAccessSignature sig=7Xtx/WAhd4QsnYBS9Ttmimb6znTLucMhBcyWCeqAO7k%3D&se=1451236361&skn=DefaultFullSharedAccessSignature&sr=https%3a%2f%2fcavenotificationhub-ns.servicebus.windows.net%2fcavenotificationhub"

"Content-type": "application/json"

"ServiceBusNotification-Format": "gcm"

}

--- END REQUEST ---

send: b'POST https://cavenotificationhub-ns.servicebus.windows.net/cavenotificationhub/messages?api-version=2013-10&test HTTP/1.1\r\nHost: cavenotificationhub-ns.servicebus.windows.net\r\nAccept-Encoding: identity\r\nContent-Length: 27\r\nAuthorization: SharedAccessSignature sig=7Xtx/WAhd4QsnYBS9Ttmimb6znTLucMhBcyWCeqAO7k%3D&se=1451236361&skn=DefaultFullSharedAccessSignature&sr=https%3a%2f%2fcavenotificationhub-ns.servicebus.windows.net%2fcavenotificationhub\r\nServiceBusNotification-Format: gcm\r\nContent-type: application/json\r\n\r\n{"data": {"msg": "Hello!"}}'

reply: 'HTTP/1.1 201 Created\r\n'

header: Transfer-Encoding header: Content-Type header: Server header: Date

--- RESPONSE ---

201 Created

Transfer-Encoding: chunked

Content-Type: application/xml; charset=utf-8

Server: Microsoft-HTTPAPI/2.0

Date: Sun, 27 Dec 2015 17:07:45 GMT

b'32gcmAPA91bFJeOUUJnrxRNn9XqLu3pAz4nAMc-XeDSv08WRhilWz9MLaEgMZd1rdM0OBcrEoDdbtBANhW9HdTt4kCL18RHwrzYzu7zuYsq1xX5D75C1B1I7KEg-f5FGqkRtUR4j662J3gpfJMRppYgD0mu8eWMUHI_OcwA2336285013042121653-349777072634954856-8The Notification was successfully sent to the Push Notification SystemgcmAPA91bFYbphBeym6XQnqzZIdbkxHCzJsiFoDaNWZG2E5tuiUMwgcFOA_5lzE3m2YIciFBwxbFaZ_HizKgknZQzHVo1bhKbOrCuZ_Ins9P4XQM945lDXyajtpisYwapMzhv3vx6HrlWNCNQ-gCJOBqhm2UCmR_x1hHg4897321139793257950-7056394320734961166-8The Notification was successfully sent to the Push Notification SystemgcmAPA91bHBCBMOfJBNxQJfuHJIoma3p1ce_QynFVtKjDqHNxnLu5123SX-Xrv89ZZqC8JfK_aR1_3_Lc1zOWfrCN1xjDQIigkbcRz2JnW7G5nKg58sEVmCt9MmyehUcKnagJv3cQOVwsgr1Cu19vY9lri-AzAGn8zyvw5663979817954802028-4194468470604299517-8The Notification was successfully sent to the Push Notification SystemgcmAPA91bHgn6cUOzl4Nkoo6C0OZedAXqY0sByqC2TuOhOmFPqFnZSvupWueKAJTUcruRgeK53YrsYMQun9Fk5E8Ud2zXiIX6DCv6uIBmLF2Se84zZ4Ed8UdiKxsW2fUUKm8bZSe2TCjR3a9oEzT34XtnGYJyfnL_aAVw7848887551469475729-2479125434514584337-8The Token obtained from the Token Provider is wronggcmAPA91bEIcQGufx0pXiEr2SUx-e4UI9mlF9v6OH4U_2eRU-suQXe1xCFJvdQYMvSy3JxctxxDX2M56pOKlIEBQEexSzQU8XM_dcXv0tOw87iOfFssX7irPn_ov8PP68LqBKFx6NfnXd-f8090852208034026590-7000564859488873545-8The Token obtained from the Token Provider is wrong'

--- END RESPONSE ---

Browser sample

I would like to see a sample of push sent to browser from php.

What is the right way to unregister azure notifications

Hi when the user logged out from the app, I won't to receive more notifications,
however actually it is still receiving notification even when user is logged out,
on logout routine I'm calling to:

NotificationsManager.stopHandlingNotifications(contextProvider.get());

however I'm still getting notification, I would appreciate any help.

Best Regards.

Cant register phone to the notifications hub server

Im getting this issue when run this code:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        SBNotificationHub* hub = [[SBNotificationHub alloc] initWithConnectionString:HUBFULLACCESS notificationHubPath:HUBNAME];
        [hub unregisterAllWithDeviceToken:deviceToken completion:^(NSError* error){
            dispatch_async(dispatch_get_main_queue(), ^{
                [hub registerNativeWithDeviceToken:deviceToken tags:tags completion:^(NSError* error) {
                    if (error != nil) {
                        NSLog(@"Error registering for notifications: %@", error);
                    } else {
                        NSLog(@"Registerd for notification");
                    }
                }];
            });
        }];
    });

Here is the error:

Error Domain=WindowsAzureMessaging Code=400 "URLRequest failed for <NSMutableURLRequest: 0x170013f20> { URL: https://<HubName>.servicebus.windows.net/<HubName>/Registrations/2044525541292942848-4457854038111768645-1?api-version=2013-04 } with status code: bad request" UserInfo={NSLocalizedDescription=URLRequest failed for <NSMutableURLRequest: 0x170013f20> { URL: https://<HubName>.servicebus.windows.net/<HubName>/Registrations/2044525541292942848-4457854038111768645-1?api-version=2013-04 } with status code: bad request}

FCM not working

Hello,

This sample still uses gcm, which will stop working the 29th of may.
I'm trying to upgrade this to fcm, but it does not work.
Too bad the sample code has not been updated to use fcm as well, otherwise that might help.

Can you update this example?

Thank you,

Tjalle

javax.net.ssl.SSLHandshakeException: Chain validation failed.

I am using Azure Could Messaging with andorid. It is working fine on device with android 6. When i run it on android 8, it ie giving error on following line.

NotificationHub hub = new NotificationHub(getNotificationHubName(),
getNotificationHubConnectionString(), this);
hub.register(FCM_token, tags).getRegistrationId();

I am using Azure Could Messaging with andorid. It is working fine on device with android 6. When i run it on android 8, it ie giving error on following line.

NotificationHub hub = new NotificationHub(getNotificationHubName(),
getNotificationHubConnectionString(), this);
hub.register(FCM_token, tags).getRegistrationId();
it is giving following error on the code "hub.register(FCM_token, tags)":

"javax.net.ssl.SSLHandshakeException: Chain validation failed."

I iterated the code in deep to azure library. And i found that it is giving the error on exactly the following line

AndroidHttpClient.newInstance(getUserAgent()).execute(request);

Node.js sample

Recently I added notification hub into my Node.js application. While the tutorial was great, I thought to check whether you guys are planning to add a Node.js sample.

Why I am asking - I would like to add it and send a PR :)

How to add Tags to SendNHRegistrationRequest method

Would it be possible to show in this walkthrough:

https://github.com/Azure/azure-notificationhubs-samples/tree/master/PushToSLPhoneApp

how to include Tags into the SendNHRegistrationRequest method?

I have tried the following:

 Payload = @"<?xml version=""1.0"" encoding=""utf-8""?>
        <entry xmlns=""http://www.w3.org/2005/Atom"">
          <content type=""application/xml"">
            <WindowsRegistrationDescription xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""http://schemas.microsoft.com/netservices/2010/10/servicebus/connect"">
              <ChannelUri>{WindowsPushChannel}</ChannelUri>
              <Tags>{Tags}</Tags>
            </WindowsRegistrationDescription >
          </content>
        </entry>";

            Payload = Payload.Replace("{WindowsPushChannel}", pushChannel);
            Payload = Payload.Replace("{Tags}", string.Join(",", tags));

            var uri = new Uri(Endpoint + HubName + "/registrations/" + ApiVersion);
            var sendRequest = WebRequest.CreateHttp(uri);
            sendRequest.Method = "POST";
            sendRequest.ContentType = ContentType;
            sendRequest.Headers[AuthHeader] = GenerateSaSToken(uri);
            sendRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), sendRequest);

But the Tags don't seem to make there way through to the Device registration page within Visual Studio:

image

Any thoughts on what I could be doing wrong?

Thanks!

Not receiving rich notifications

NotificationExtensionService is installed, Provisioning is correct, Permissions set, Certs exported/imported and associated properly I get the notifications but no buttons, no images.

Visual Studio 2017
Xamarin ios 11.4.1 on phone and ipad

I've tried swiping down, 3d touch, swipe left on notification center notification and choose View. Nothing displays. I can't figure out how to debug the notification service but my breakpoints are never hit.

I'm using this payload to test to successfully send
{
"aps" : {
"alert" : {
"title" : "Game Request",
"body" : "Bob wants to play poker",
"action-loc-key" : "calendar"
},
"badge" : 1,
"sound" : "default",
"mutable-content" : 1
},
"data" :{
"attachment-url": "https://m.popkey.co/987552/NGLb3.gif"
},
}

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.