Introducing Push to User for Visual Studio App Center

John Wargo [MSFT]

We made some recent changes to Visual Studio App Center that enable our customers to associate app users with their data in App Center. App Center customers can use this user association to send push notifications to specific users through App Center Push. In this article, I’ll explain how it all works.

Identifying App Users

The first change we made was to update the SDK to deliver a way for apps to inform App Center of each app user’s identity. Apps validate their app user’s identity using whatever authentication method the app developer wants, then calls an SDK method to set the user’s identity in App Center. In this example, the user’s ‘identity’ is whatever the developer wants it to be; it can be a username, email address, phone number, or even a unique ID generated by the app. With the user’s identity set, customers can view Analytics and Diagnostics data for specific users, plus send notifications to users as well. You can learn more about this feature in the App Center blog and see an example of the SDK method for Android in the App Center documentation.

Another way to identify app users is through the App Center Auth service. With Auth, developers add a few lines of code to their apps, and App Center manages the in-app authentication process (using third-party identity providers or the traditional username and password approach). Once the app user signs in, the App Center SDK automatically registers the user’s identity in App Center, enabling developers to view Analytics and Diagnostics data for specific users, plus send notifications to users. You can learn more about this feature in the App Center blog.

Sending Notifications to Users

Now that you know all about how to identify users in App Center, I’ll show you how to send notifications to users instead of specific devices. First a little background…

In traditional mobile app notification systems, each device running the app registers for notifications through the notification service associated with the mobile device platform (Android devices register with Google, and iOS devices register with Apple). During registration, the app receives a push token from the platform’s notification service that the developer can use, through the app’s backend systems, to send notifications to the device.

Developers building apps like this must generally write the code in the app to register the device for notifications, then send the user’s identity and the device token to the app’s backend system for storage. When it comes time to send a notification, the backend identifies the user or users that need notified, digs up the device tokens associated with each targeted user, and sends the notification through the appropriate third-party notification service (a different one for each target platform).

With App Center Push, most of this is taken care of for you. The App Center SDK handles the device registration process and stores the user identity along with the device token inside of App Center. All you must do is capture the user identity and store it somewhere on the app’s backend so you’ll have it later when you’re ready to notify users. App Center will map user identities to all the devices associated with the user and send notifications to all of them on your command.

App Center Push supports two ways to send notifications to users:

  • Using the App Center Portal
  • Using the App Center API

The following sections describe each approach in detail.

Using the App Center Portal

We expect that most customers will send user notifications using the App Center API simply because when you have an app with thousands or millions of users, you probably won’t want to hop over to the App Center Portal for this purpose. We still want to support the manual notification process, so sending notifications to users is just an additional option in the Send Notification wizard shown in Figure 1.

A screenshot of a cell phone Description automatically generated

 

To send notifications to users, select the User list option shown in the figure. If you are not using App Center Auth to manage user identities (why not?) then App Center defaults to asking for a comma-separated list of user identifiers as shown in Figure 2. The input field expects a comma-separated list of string values representing the user identity values the app set using the App Center SDK. We expect apps will use something like email address, but, remember, it could be anything the developer’s heart desires.

A screenshot of a social media post Description automatically generated

 

If the app in App Center is configured for App Center Auth, then the portal experience changes as shown in Figure 3. Here, App Center customers can search for user identities as shown in the figure. As you type, the portal searches the list of authenticated users, enabling you to quickly find, and select, user identities to use for the notification.

A screenshot of a cell phone Description automatically generated

 

At this point, the notification process remains the same, simply click the Next button to complete the wizard and send the notification. To learn more about this feature, refer to the App Center Push to User documentation.

Using the App Center API

For the API approach, we added two notification_target options to the existing /push/notifications API.

To send a notification to user identities set using the SDK, specify a notification_target type of user_ids_target as shown in the following example:

{
  "notification_target": {
    "type": "user_ids_target",
    "user_ids": [anna@company.com, joe@company.com, ashwin@company.com]
  },
  "notification_content": {
    "name": "NOTIFICATION_NAME",
    "title": "NOTIFICATION_TITLE",
    "body": "NOTIFICATION_MESSAGE_BODY",
    "custom_data": {
      "additionalProp1": "PROPERTY_1",
      "additionalProp2": "PROPERTY_2",
      "additionalProp3": "PROPERTY_3"
    }
  }
}

 

Populate the user_ids array with the list of user identifiers (string values) to which you want to send the notification. Since the user identity comes from the developer’s code that sets the identity through the SDK, the user identity can be any string value: user name, email address UUID, anything.

To send a notification to user identities set using the App Center Auth, specify a notification_target type of account_ids_target as shown in the following example:

{
  "notification_target": {
    "type": "account_ids_target",
    "account_ids": [e340c9bb-07af-4556-9d36-2453c6c0f4f1, 3bd79109-72d9-43d9-b7de-2f46fd617778, 55d6aa74-673a-49d3-87dc-b37741b05a11]
  },
  "notification_content": {
    "name": "NOTIFICATION_NAME",
    "title": "NOTIFICATION_TITLE",
    "body": "NOTIFICATION_MESSAGE_BODY",
    "custom_data": {
      "additionalProp1": "PROPERTY_1",
      "additionalProp2": "PROPERTY_2",
      "additionalProp3": "PROPERTY_3"
    }
  }
}

 

Populate the account_ids array with the list of App Center Identity Account identifiers (string values) to which you want to send the notification. These identifiers are maintained internally by the App Center Identity service, so you’ll have to either pull them manually from the App Center Portal, or build a backend service to store and associate them with your app users.

To learn more about this feature, refer to the App Center Push to User API documentation.

4 comments

Discussion is closed. Login to edit/delete existing comments.

  • Jackson Wright 0

    Hey John! I’m thinking this update may have broken the old way of using the API to target just a few devices at a time using the “devices” parameter. It seems like using “devices” to list install IDs just blasts out the notification to all registered devices of my application. This coincidentally started misbehaving at the same time this update went live. This is the API endpoint I am using. https://openapi.appcenter.ms/#/push/Push_Send
    Thanks!

    • John Wargo Microsoft employee 0

      Jackson, No, this feature has been in the product for a few weeks now. What you experienced was an issue with the service yesterday that has since been resolved.

  • Varanasi, Prasanth 0

    Hi John. Any updates to the AppCenter Push for sending the notifications even when the app is not running? We had implemented the AppCenter Push SDKs for both Android & iOS. And, the notifications aren’t received when the Xamarin Forms app is not running.

Feedback usabilla icon