Reputation: 602
I have created a Notification Hub using this guide and these instructions (for how to add Firebase to Azure).
When I send using Test Send on Azure, the push notification is send successfully. But when I send it using their Console Example in the previous mentioned guide, it simply crashes when using SendGcmNativeNotificationAsync
-method.
What can be wrong?
My namespace contains letters and a -
, but my name for the hub contains _
too. Can that be the problem (and if it is, why did they not tell me during creation)?
EDIT: Modified code
var connectionStr = ServiceBusConnectionStringBuilder.CreateUsingSharedAccessKey(new Uri({uri}), "DefaultSendSharedAccessSignature", "Ln4em6ZqeukRS3y1Hgq/3m5V2S51IBIkG7tk+MAfO/Y=");
var hub = NotificationHubClient.CreateClientFromConnectionString(connectionStr, {hub-name});
await hub.SendGcmNativeNotificationAsync("{ \"data\" : {\"message\":\"Hello from Azure!\"}}");
Console.ReadLine();
Upvotes: 1
Views: 1025
Reputation: 188
Try something like this:
private static async void SendNotificationAsync()
{
NotificationHubClient hub = NotificationHubClient
.CreateClientFromConnectionString("<connection string with full access>", "<hub name>");
var notif = "{ \"data\" : {\"message\":\"" + "Hola" + "\"}}";
await hub.SendGcmNativeNotificationAsync(notif);
}
Obtained from: http://www.c-sharpcorner.com/blogs/sending-notification-from-a-console-application-using-notification-hubs
The connection string can be found in your Notification Hub (Access Policies):
It worked for me for a simple console App Test.
Upvotes: 1