- Home
- Documentation
- Client Setup
- iOS
- Create App
- Get the SDK
- Enable Capability
- Register Devices
- Handle Notifications
- Subscribe to Topics
- Setup APNs Authentication
- Send Test Notification
- Android
- Create App
- Get the SDK
- Register Devices
- Modify Launcher Activity
- Modify AndroidManifest
- Setup BroadcastReceiver
- Parse Notification Data
- Subscribe to Topics
- Send Test Notification
- Web Push
- Create App
- Get the SDK
- Register Visitors
- Handle Notifications
- Subscribe to Topics
- Send Test Notification
- Additional Platforms
- Ionic
- Flutter
- Python
- macOS
- Angular
- Electron
- Cordova
- Capacitor
- PhoneGap
- React Native
- MAUI (Android)
- Xamarin (Android)
- Migration Guides
- Backend Setup
-
API Reference - SDK Reference
- Additional Resources
Got Feedback?
We'd love to hear what you have to say about our documentation. Let us know how we can improve it.
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.
Please select your iOS project type for the appropriate instructions:
Simply add the following code to subscribe the user to a topic:
// Initialize Pushy SDK
let pushy = Pushy(UIApplication.shared)
// Subscribe the user to a topic
pushy.subscribe(topic: "news", handler: { (error) in
// Handle errors
if error != nil {
return print("Subscribe failed: \(error!.localizedDescription)")
}
// Subscribe successful
print("Subscribed to topic successfully")
})
// Initialize Pushy SDK
Pushy* pushy = [[Pushy alloc]init:[UIApplication sharedApplication]];
// Subscribe the user 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-_.]{1,100}
. You may also pass in a string array with multiple topics (limited to 100).
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.