How to send push notifications to a running app with Visual Studio
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.
- 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.
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:
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), use the Windows Store templates. If your client uses the MPNS APIs (in the namespace Microsoft.Phone.Notification), 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, The tile template catalog and the reference documentation for the XML schema.
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.
- 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.
- 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