Notifications
Notifications Feature
In LaunchYourApp we use Expo Notifications to send push notifications to users. This guide will show you how to set up and use Expo Notifications in your app. We already have it set up in the project, so you just need to follow the instructions below.
Import
import * as Notifications from 'expo-notifications';
import { registerForPushNotificationsAsync } from './path-to-notifications-utils';
Usage
Set Notification Handler
Configure how notifications should be handled when received:
Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: false,
shouldSetBadge: false,
}),
});
Register for Push Notifications
Register a user for push notifications and send the token to your server:
await registerForPushNotificationsAsync(userId);
API
registerForPushNotificationsAsync
async function registerForPushNotificationsAsync(userId: string): Promise<void>
Registers the device for push notifications and sends the Expo push token to your server.
Parameters
userId: string
- The unique identifier for the user.
Returns
Promise<void>
- A promise that resolves when the registration is complete.
Configuration
Testee
Make sure to replace 'your-project-id'
with your actual Expo project ID when calling getExpoPushTokenAsync
.
Server Integration
The registerForPushNotificationsAsync
function sends a POST request to https://example.com/
with the user ID and Expo push token. Ensure your server is set up to receive and process this data.
Additional Resources
For more information on Expo notifications, refer to the official Expo documentation.