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
- A Microsoft Azure subscription. If you don't have a subscription, sign up for a free trial.
- A published mobile service. If you don't have one, create one and publish it.
- A client app that's correctly configured to receive notifications. See Quickstart: Adding push notifications to a mobile service.
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.
In Server Explorer, expand the Notification Hubs node.
Open the shortcut menu for the notification hub that you want to use to send your notification, and choose Send a notification.
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"))
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. |
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.
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.
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.
Related topics
Quickstart: Adding push notifications to a mobile service
Quickstart: Add a mobile service
Notification Hubs Tutorials and Guides
Getting Started with Notification Hubs