ExpoNotificationsAdapter
Notification adapter for Expo projects using expo-notifications.
Work in Progress: The notification adapter APIs are under active development and may change in future releases.
The ExpoNotificationsAdapter integrates with Expo's notifications library for push notification handling.
Installation
npx expo install expo-notifications expo-device expo-constantsUsage
import { TeardownCore } from '@teardown/force-updates';
import { ExpoNotificationsAdapter } from '@teardown/force-updates/expo';
import { ExpoDeviceAdapter } from '@teardown/force-updates/adapters/expo';
import { MMKVStorageAdapter } from '@teardown/force-updates/adapters/mmkv';
const teardown = new TeardownCore({
org_id: 'your-org-id',
project_id: 'your-project-id',
api_key: 'your-api-key',
storageAdapter: new MMKVStorageAdapter(),
deviceAdapter: new ExpoDeviceAdapter(),
notificationAdapter: new ExpoNotificationsAdapter(),
});
// Access via NotificationsClient
if (teardown.notifications) {
const status = await teardown.notifications.requestPermissions();
if (status.granted) {
const token = await teardown.notifications.getToken();
console.log('Expo push token:', token);
}
}Import Path
import { ExpoNotificationsAdapter } from '@teardown/force-updates/expo';API
All methods are accessed via NotificationsClient, not directly on the adapter.
requestPermissions()
Request notification permissions:
const status = await teardown.notifications.requestPermissions();
// Returns: { granted: boolean, canAskAgain: boolean }getToken()
Get the Expo push token:
const token = await teardown.notifications.getToken();
// Returns: "ExponentPushToken[xxxxxx]" or nullonNotificationReceived()
Subscribe to foreground notifications:
const unsubscribe = teardown.notifications.onNotificationReceived((notification) => {
console.log('Received:', notification.title);
});
// Cleanup
unsubscribe();onNotificationOpened()
Subscribe to notification taps:
const unsubscribe = teardown.notifications.onNotificationOpened((notification) => {
console.log('User tapped:', notification.title);
});
// Cleanup
unsubscribe();onTokenRefresh()
Subscribe to token changes:
const unsubscribe = teardown.notifications.onTokenChange((token) => {
console.log('New token:', token);
});
// Cleanup
unsubscribe();onDataMessage()
Subscribe to data-only/silent messages:
const unsubscribe = teardown.notifications.onDataMessage((message) => {
console.log('Data message:', message.data);
});
// Cleanup
unsubscribe();Configuration
app.json / app.config.js
{
"expo": {
"plugins": [
[
"expo-notifications",
{
"icon": "./assets/notification-icon.png",
"color": "#ffffff"
}
]
]
}
}Android
For FCM integration, add your google-services.json to the project root.
iOS
Push notifications require:
- Apple Developer account
- Push notification capability
- APNs certificate or key
Platform
Returns NotificationPlatformEnum.EXPO
Requirements
expo-notifications>= 0.32expo-device>= 8.0.0expo-constants>= 17.0.0- EAS Build or dev client (not Expo Go)