Expo

SDK oficial @daertech/pushhub-react-native con su plugin de Expo, o expo-notifications por REST.

En Expo, el SDK oficial es el mismo de React Native. Trae un config plugin que, durante npx expo prebuild o el build de EAS, configura APNs y agrega la extensión de imágenes y botones de iOS.

Instalación

npx expo install @daertech/pushhub-react-native @react-native-firebase/app @react-native-firebase/messaging expo-build-properties

En app.json:

{
  "expo": {
    "ios": { "bundleIdentifier": "com.tuempresa.app", "googleServicesFile": "./GoogleService-Info.plist" },
    "android": { "package": "com.tuempresa.app", "googleServicesFile": "./google-services.json" },
    "plugins": [
      "@react-native-firebase/app",
      "@react-native-firebase/messaging",
      ["expo-build-properties", { "ios": { "useFrameworks": "static" } }],
      ["@daertech/pushhub-react-native", { "apsEnvironment": "production", "iosNotificationServiceExtension": true }]
    ]
  }
}

Opciones del plugin:

Opción Por defecto Descripción
apsEnvironment development production para TestFlight y App Store.
iosNotificationServiceExtension true Agrega el target PushHubNotificationService, para imágenes y botones, y lo registra para EAS.
developmentTeam — Team ID de Apple para firmar la extensión, si no usas EAS.
iosDeploymentTarget 15.1 Versión mínima de iOS de la extensión.

Para usar el Installation ID de Firebase, agrega installationIdEnabled: true a las opciones del plugin @react-native-firebase/messaging; el SDK lo detecta solo.

El uso en código es igual que en React Native. En Expo, el dispositivo se registra con framework: "expo".

import { PushHub } from '@daertech/pushhub-react-native';

PushHub.init({ appKey: 'pk_live_TU_LLAVE_PUBLICA', iosNotificationServiceExtension: true });

Sin SDK (expo-notifications por REST)

Con expo-notifications, el token nativo es:

import * as Notifications from 'expo-notifications';
import { Platform } from 'react-native';

export async function initPush() {
  const { status } = await Notifications.requestPermissionsAsync();
  if (status !== 'granted') return;
  const { data: token } = await Notifications.getDevicePushTokenAsync();   // token nativo
  await fetch('https://api.pushhub.daertec.com/v1/devices', {
    method: 'POST',
    headers: { Authorization: 'Bearer pk_live_TU_LLAVE_PUBLICA', 'Content-Type': 'application/json' },
    body: JSON.stringify({ token, platform: Platform.OS, framework: 'expo', environment: 'auto' }),
  });
}

Notifications.setNotificationHandler({
  handleNotification: async () => ({ shouldShowBanner: true, shouldShowList: true, shouldPlaySound: true, shouldSetBadge: true }),
});
Notifications.addNotificationResponseReceivedListener((r) => {
  const data = r.notification.request.content.data;   // _phid, deepLink, tus datos
});

En Android, crea el canal con Notifications.setNotificationChannelAsync('general', { name: 'Avisos', importance: Notifications.AndroidImportance.HIGH }).