Toast notifications c#

Asked

Viewed 212 times

1

Hello, How can I use Azure to notify the user that you have new content in the app? I am creating a project on c# for Windows 10. Thanks in advance.

1 answer

3

You must use the service of Azure Notification Hub.

Push notifications to any platform and back-end

  • Reach all major platforms: iOS, Android, Windows, Kindle, Baidu Use any back-end: cloud or local
  • Quickly push-stream to millions of mobile devices with a single call to the API
  • Customize push notifications by user, language, and location
  • Dynamically define and notify user segments
  • Scale to millions of mobile devices instantly

To trigger back-end notification:

var hub = NotificationHubClient
            .CreateClientFromConnectionString("Endpoint=sb://NOME_DO_SEU_APP.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=CHAVE_DO_SEU_APP",
            "NOME_DO_SEU_APP");

var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">Bem vindos ao VSSummit 2015</text></binding></visual></toast>";

var toastWithImage = @"<toast><visual><binding template=""ToastImageAndText01""><image id=""1"" src=""https://cdn1.iconfinder.com/data/icons/metro-ui-icon-set/512/Visual_Studio_2012.png"" /><text id=""1"">Bem vindos ao VSSummit15!</text></binding></visual></toast>";

hub.SendWindowsNativeNotificationAsync(toast).Wait();

There are other models/templates simple message, with or without image, with or without title, with counters, etc. See more models of Toast Notifications.

And to make your app receive notifications:

private async void InitNotificationHubAsync()
{
    var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

    var hub = new NotificationHub("NOME_DO_SEU_APP", "Endpoint=sb://NOME_DO_SEU_APP.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=CHAVE_COMPARTILHADA_DO_SEU_APP");

    await hub.RegisterNativeAsync(channel.Uri);
}

In the my Github repository has an example of how to consume the service:

Example of Azure Notification Hub.

  • Thanks for the help Thiago :D

  • I followed the tutorial to the letter. In debug mode, everything works perfect. Then I send the app to the store, down and open it. At this point it closes without explanation. I have already done the test and if you remove the code, the app works correctly again. Any hints?

  • 1

    Well, there’s not much to say. You just need a way to get the Exception that’s going on and send it to you. There are some tutos on the web explaining - I don’t have any to recommend. Try running RELEASE on your device, see if anything changes. If you don’t solve, implement Azure Application Insights, it can pick up some app behaviors.

  • @Leandrolap, if you agree, can mark the answer as the ideal, please? :)

  • Azure Notifications hub serves to push Notifications to a pwa? web application in case it would be in angular

Browser other questions tagged

You are not signed in. Login or sign up in order to post.