Get a device's unread mass notification count with getUnreadNotificationInboxCount.
Premium has no inbox
On Premium, every inbox endpoint answers 201 with an explanation ("Your current Native Notify membership cannot access notification inbox features…"), so the SDK shows an empty inbox and an unread count of 0 until you upgrade. See what each plan includes.
Get the unread count
Call getUnreadNotificationInboxCount from the header or footer component that holds your inbox icon:
import React, { useState, useEffect } from 'react';
import { getUnreadNotificationInboxCount } from 'native-notify';
export default function Header() {
const [unreadNotificationCount, setUnreadNotificationCount] = useState(0);
useEffect(() => {
const fetchUnreadCount = async () => {
try {
const unreadCount = await getUnreadNotificationInboxCount(
yourAppId,
"yourAppToken"
);
console.log("unreadCount: ", unreadCount);
setUnreadNotificationCount(unreadCount);
} catch (error) {
console.error("Error fetching unread notification count: ", error);
}
};
fetchUnreadCount();
}, []);
return (
// ... show a bubble over your icon when unreadNotificationCount is above 0
);
}
It returns 0 on web and on a device that can't mint an Expo push token.
Count accuracy
The count can reset
The count is tracked per device by Expo push token, so it resets to the total number of notifications whenever a device gets a new token, for example after a reinstall.
To soften it, show an empty bubble whenever the count is above 0 instead of a number, or show the number only under a limit such as 5 or 10. For an always-accurate count, use an indie notification inbox: it counts per Indie Push ID, so a logged-in user's count holds across devices and reinstalls.