Notification center
Show a badge with the number of notifications the user has not seen in the community, to bring them back to what is new.
Android availableiOS availableFlutter availableReact Native availableUnity available
Before you begin
- Complete the Quickstart: the SDK is initialized and the community screen opens in your app.
- Pick where the badge goes in your app, for example on the tab or the button that opens the community.
How it works
The community has its own notification center, inside the Octopus UI: it lists what other members did that concerns the user. The not-seen count is the number of entries the user has not seen there yet.
The count does not depend on push notifications: it works whether or not you set up Push notifications, and the user does not need to grant the notification permission.
The SDK publishes the count and updates it when it changes; ask for a refresh from the server when you need the latest value, for example when your app comes to the foreground.
Show the not-seen count
- Android
- iOS
- Flutter
- React Native
- Unity
Collect OctopusSDK.notSeenNotificationsCount, a Flow<Int>. updateNotSeenNotificationsCount() is a suspend function that fetches the count and returns it as an OctopusResult<Int, Nothing>:
lifecycleScope.launch {
OctopusSDK.notSeenNotificationsCount.collect { count ->
// Update your badge
}
}
lifecycleScope.launch {
OctopusSDK.updateNotSeenNotificationsCount()
}
The Android sample's SettingsViewModel collects notSeenNotificationsCount for its Debug info row and Community tab badge, and ScenariosViewModel calls updateNotSeenNotificationsCount().
Subscribe to $notSeenNotificationsCount, the publisher of the @Published Int notSeenNotificationsCount of your OctopusSDK instance. updateNotSeenNotificationsCount() is an async throws function that fetches the count from the server; the publisher then emits the new value:
import Combine
var cancellables = Set<AnyCancellable>()
octopus.$notSeenNotificationsCount
.sink { count in
// Update your badge
}
.store(in: &cancellables)
Task {
try await octopus.updateNotSeenNotificationsCount()
}
The community tab of the iOS sample app shows a full example.
Listen to OctopusSDK.notSeenNotificationsCount, a Stream<int>, and refresh it with updateNotSeenNotificationsCount():
OctopusSDK.notSeenNotificationsCount.listen((count) {
// Update your badge
});
await OctopusSDK().updateNotSeenNotificationsCount();
addNotSeenNotificationsCountListener emits the current count after initialization, then every change. Refresh it with updateNotSeenNotificationsCount():
import {
addNotSeenNotificationsCountListener,
updateNotSeenNotificationsCount,
} from '@octopus-community/react-native';
const subscription = addNotSeenNotificationsCountListener((count) => {
// Update your badge
});
await updateNotSeenNotificationsCount();
// When you no longer need it:
subscription.remove();
Subscribe to OctopusSDK.OnNotSeenNotificationsCount and refresh it with UpdateNotSeenNotificationsCount():
OctopusSDK.OnNotSeenNotificationsCount += (int count) =>
{
// Update your badge
};
OctopusSDK.UpdateNotSeenNotificationsCount();
Next steps
- Display the community: open the community when the user taps the badge.
- Push notifications: notify the user outside your app when other members interact with them.