Documentation

Subscribe to Topics (Optional)


Optionally subscribe the device 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 devices by specifying their tokens.

Please select your project type for the appropriate instructions:

Swift
Objective-C

Simply add the following code to subscribe a registered device to a topic:

// Initialize Pushy SDK
let pushy = Pushy(UIApplication.shared)

// Subscribe the device to a topic
pushy.subscribe(topic: "news", handler: { (error) in
    // Handle errors
    if error != nil {
        return print("Subscribe failed: \(error!)")
    }
    
    // Subscribe successful
    print("Subscribed to topic successfully")
})
// Initialize Pushy SDK
Pushy* pushy = [[Pushy alloc]init:[UIApplication sharedApplication]];

// Subscribe the device to a topic
[pushy subscribeWithTopic:@"news" handler:^(NSError *error) {
    // Handle errors
    if (error != nil) {
        return NSLog(@"Subscribe failed: %@", error);
    }
    
    // Subscribe successful
    NSLog(@"Subscribed to topic successfully");
}];

Note: 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 devices subscribed to a certain topic by specifying the topic name (prefixed with /topics/) as the to parameter in the Send Notifications API.