Subscribe to Topics

Optionally subscribe the user to one or more topics to target multiple users with a shared interest when sending notifications.

Depending on your app's notification criteria, you may be able to leverage topics to simply the process of sending the same notification to multiple users. If your app only sends personalized notifications, skip this step and simply target individual users by their unique device tokens.

Simply add the following code to subscribe the user to a topic:

// Check if the user is registered
if (Pushy.isRegistered()) {
    // Subscribe the user to a topic
    Pushy.subscribe('news').catch(function (err) {
        // Notify user of failure
        alert('Subscribe failed: ' + err.message);

Note: Make sure to replace news with your own case-sensitive topic name that matches the following regular expression: [a-zA-Z0-9-_.]+. You may also pass in a string array with multiple topics.

You can then notify multiple users subscribed to a certain topic by specifying the topic name (prefixed with /topics/) as the to parameter in the Send Notifications API.