Основная проблема состоит в том, что, хотя уведомления о шкале iOS-push- Состояние. Поставщик: обмен сообщениями об облако огненной базы (FCM) < /p>
Симптом: уведомления получены и отображаются ОС, но обработчики JS (Onmessage, BetbackgroundMessageHandler, OnnotificationOpenApp) не называются. Шаги: < /li>
< /ol>
Возможности xcode: уведомления Push и фоновые режимы (удаленные уведомления) включены для цели. Разрешения от пользователя.
- React Native Javascript Code (не запускает)
Это код, расположенный в ./index.js и ./app.tsx.
< /code>
messaging().setBackgroundMessageHandler(async remoteMessage => {// THIS LINE IS NEVER LOGGED when in the background/quit state.console.log('
< /code>
./App.tsx (Foreground Listeners):
import messaging from '@react-native-firebase/messaging';import { useEffect } from 'react';import { Alert } from 'react-native';
< /code>
// ... Inside App component ...
useEffect(() => {// Listener for messages when the app is in the foreground (active)const unsubscribe = messaging().onMessage(async remoteMessage => {// THIS IS NEVER TRIGGERED (no Alert or console log)console.log('A new FCM message arrived!', remoteMessage);Alert.alert(remoteMessage.notification.title,remoteMessage.notification.body);});return unsubscribe;}, []);
< /code>
useEffect(() => {// Listener for when the user taps on a notification to open the app (background/quit)const unsubscribe = messaging().onNotificationOpenedApp(remoteMessage => {// THIS IS NOT FIRINGconsole.log('App opened from background via notification:', remoteMessage);});
< /code>
// Check for notification that opened the app from the quit state
messaging()
.getInitialNotification()
.then(remoteMessage => {
if (remoteMessage) {
// THIS IS NOT FIRING
console.log('App opened from quit state via notification:', remoteMessage);
}
});
return unsubscribe;
< /code>
}, []);
Подробнее здесь: https://stackoverflow.com/questions/797 ... otificatio
Мобильная версия