Expo Push (Classic)

Create a mass notification inbox

Fetch your mass notifications with getNotificationInbox and build your own inbox screen.

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.

Fetch the inbox

Call getNotificationInbox from a function component and keep the rows in state:

import React, { useState, useEffect } from 'react';
import { getNotificationInbox } from 'native-notify';

export default function NotificationInbox() {
    const [data, setData] = useState([]);

    useEffect(() => {
        const fetchNotifications = async () => {
            try {
                const notifications = await getNotificationInbox(
                    yourAppId,
                    "yourAppToken",
                    20, // take
                    0   // skip
                );
                console.log("notifications: ", notifications);
                setData(notifications);
            } catch (error) {
                console.error("Error fetching notifications: ", error);
            }
        };

        fetchNotifications();
    }, []);

    return (
      // ... render an inbox from data
    );
}
  • take defaults to 20 in native-notify v5+. v4, and a raw REST call without take, get the server's default of 10. skip defaults to 0.
  • Each row's pushData is the JSON string you sent. Read it with JSON.parse(row.pushData).
  • Fetching marks every notification in the app's inbox as read for this device, on a device that can mint an Expo push token.

Exact pagination

getNotificationInboxPage(appId, appToken, take, skip) returns one page of rows plus the server's total row count, read from the X-Total-Count header, so "load more" can be exact:

import { getNotificationInboxPage } from 'native-notify';

const { rows, total } = await getNotificationInboxPage(
  yourAppId,
  "yourAppToken",
  20, // take
  0   // skip
);

console.log(rows.length, "of", total); // total is null when the server doesn't send the header

It marks the inbox read too, unless you use the option below. getNotificationInbox returns the rows array alone.

Per-notification read state

Requires native-notify v5.2+. Pass { perNotification: true } as the fifth argument to get each row's real read flag for this device and skip the mark-all-read. Then mark each row read when the user opens it:

import { getNotificationInboxPage, markMassNotificationRead } from 'native-notify';

const { rows, total } = await getNotificationInboxPage(
  yourAppId,
  "yourAppToken",
  20, // take
  0,  // skip
  { perNotification: true }
);

rows[0].read; // false until this device has read it

// Mark ONE row read when it is opened (best-effort — resolves false, never throws).
// Pass the ids unless you set them once with NativeNotify.init():
await markMassNotificationRead(rows[0].notification_id, yourAppId, "yourAppToken");

Expo push token

Read state is tracked per device by Expo push token. Where none can be minted (web, Expo Go on Android, a simulator or emulator without push support), every row reports read: false and can't be marked.

markMassNotificationRead(notificationId, appId?, appToken?) resolves true when the server accepted the mark, and false, without throwing, when there is no device token or the call fails. Without a notificationId it resolves false and sends nothing, because the endpoint's id-less form marks the whole inbox read.

useNotificationInbox() and the prebuilt components expose the same feature as the perNotificationRead prop.