Ler em inglês

Compartilhar via


How to send push notifications to a running app with Visual Studio

[This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation]

When you develop or test apps that use push notifications, you might want to send a notification to your app without having to modify your mobile service code. Visual Studio provides a convenient way to do this through Server Explorer.

Prerequisites

Instructions

Step 1: To send a push notification with Visual Studio

During the development and testing phase of an app, you might want to send push notifications to test your app's response to them. You might also want to trigger certain behavior in an app that's running on a remote device from a development machine. If the behavior is triggered by push notifications, you can compose and send a notification from Visual Studio that will trigger the desired behavior.

  1. In Server Explorer, expand the Notification Hubs node.

  2. Open the shortcut menu for the notification hub that you want to use to send your notification, and choose Send a notification.

  3. Choose whether to send to a specific tag or broadcast to all registered clients. If you want to send to a tag, choose the Tag option and specify the name of the tag. In this case, an app will receive the notification only if it has registered for the tag, using code like this:

    await App.mymobileserviceClient.GetPush().RegisterNativeAsync(channel.Uri, new string[] { "tag1", "tag2" });
    
    Await App.mymobileserviceClient.GetPush().RegisterNativeAsync(channel.Uri, New String() { "tag1", "tag2" })
    
    mymobileserviceclient1234Client.push.registerNative(channel.Uri, new Array("tag1", "tag2"))
    
  4. Choose the type of notification you want to send based on the target application type. The following notification types are available.

Message type Format Description
Windows Store Toast WNS XML Text that pops up on the Windows Store client's screen.
Windows Store Tile WNS XML An update to a Windows Store tile.
Windows Store Badge WNS XML An icon or symbol that appears on a Windows Store tile.
Windows Store Raw Binary Arbitrary raw data.
Windows Phone Toast MPNS XML Text that pops up on the phone's screen.
Windows Phone Tile MPNS XML An update to a Windows Phone tile.
Windows Phone Raw MPNS XML Arbitrary raw data.
iOS Default JSON Message compatible with iOS clients.
Android Default JSON Message compatible with Android clients.
Custom Template Default JSON Message that works with all types of clients.
  **Tip**  The types of notifications you send depend on the specific notification types that your client app supports. Some Windows Phone clients support the WNS notification type, but others use the Microsoft Push Notification Service (MPNS) type. If your client app uses the WNS client APIs (in the namespace [Windows.Networking.PushNotifications](https://msdn.microsoft.com/library/windows/apps/windows.networking.pushnotifications.aspx)), use the Windows Store templates. If your client uses the MPNS APIs (in the namespace [Microsoft.Phone.Notification](https://msdn.microsoft.com/library/windowsphone/develop/microsoft.phone.notification.aspx)), use the Windows Phone templates.   Depending on what you choose from the list, a template for that type of message appears in the Body text box. For an explanation of the different types of notification templates you can use for Windows Store apps, see [The toast template catalog](hh761494\(v=win.10\).md), [The tile template catalog](hh761491\(v=win.10\).md) and the reference documentation for the [XML schema](https://msdn.microsoft.com/library/windows/apps/br212853.aspx). ![](images/Dn614131.SendNotifications_WindowsStore(en-us,WIN.10).png) **Tip**  If you have multiple types of clients that accept messages in different formats, send different messages to each type of client. Each type of client only receives messages in the formats it supports.  
  1. Edit the body to specify your message. When editing messages in the XML format, don't change the XML or JSON structure, just change the values inside the XML or JSON elements, such as the title and background image. Make sure that the result is correctly formatted XML or JSON.

  2. View the status of your notification in the Message Result area.

    Tip  The test message is sent to no more than 10 random registered clients.

     

  3. If sending the notification fails, make sure that a client app is registered for push notifications from the notification hub you're using, and that the type of the message you chose is appropriate for at least one client app.

Quickstart: Adding push notifications to a mobile service

Quickstart: Add a mobile service

Notification Hubs Tutorials and Guides

Notification Hubs Overview

Getting Started with Notification Hubs

Notify users with Notification Hubs

Using Notification Hubs to send breaking news