Skip to content
Gravity Logo / Docs Gravity home
Browse documentation
Documentation/Gravity Server

Push Notifications

If you purchased a Gravity Native or Gravity Power plan, you can send push notifications from the server to mobile devices on iOS or Android.

When a user provides permission in-app to send push notifications, a push token for their device is stored in the database.

Sending Push Notifications

Pass one object to notification.send. Supply the stored device tokens and a message with a title and body.

const notification = require('./helper/notification');

async function notifyDevices(tokens) {
  await notification.send({
    tokens,
    message: {
      title: 'New user',
      body: 'A new user has signed up.'
    }
  });
}

Info

You can also pass data and sounds, please refer to the Expo documentation for more information.

You will probably only ever send one-off notifications based on a user’s actions, however if you need to send hundreds of messages simultaneously, you may want to consider bulk sending.

Removing Tokens

Expo can return DeviceNotRegistered for a previously valid device. The current receipt handler in helper/notification.js compares the ticket ID to the receipt object when looking up the token. Review that lookup before relying on automatic token removal.