1-eneable возможностей в xcode
- gope apply → signing & signing of & signings & paculties
. /> < /li>
add: < /p>
Push Notifications - Background Modes ➝ Включить удаленные уведомления
2. Настройте APN в Firebase < /h3>
- Загрузите свой клавиш APNS AUTH APNS .p8 < /strong> на консоль Firebase → Настройки проекта → Обмен облачными сообщениями < /li>
< /ul>
3. Установить необходимые библиотеки < /h3>
npm install @notifee/react-native @react-native-firebase/app @react-native-firebase/messaging
cd ios && pod install && cd ..
< /code>
4. Добавьте свой собственный звуковой файл
Создайте звуковой файл в. ios/yourappname/ - Перетащите его в навигатор проекта xcode → Убедитесь «Скопировать при необходимости». Проверяется
5. Отправить уведомление со звуком через fcm < /h3>
{
"to": "",
"notification": {
"title": "New Alert",
"body": "Sound test",
"sound": "custom_sound.wav"
},
"priority": "high"
}
- do не включить Silent: true или content_available: true
import messaging from '@react-native-firebase/messaging';
import notifee, {
AndroidImportance,
AndroidVisibility,
EventType,
} from '@notifee/react-native';
async function sendLocalNotification(message) {
await notifee.requestPermission({ sound: true, alert: true });
const channelId = await notifee.createChannel({
id: 'default',
name: 'Default Channel',
sound: 'default',
importance: AndroidImportance.HIGH,
visibility: AndroidVisibility.PRIVATE,
});
// Display a notification
await notifee.displayNotification({
title: message.notification.title,
body: message.notification.body,
data: message?.data,
ios: {
sound: 'custom_sound.wav',
},
android: {
channelId,
importance: AndroidImportance.HIGH,
visibility: AndroidVisibility.PRIVATE,
sound: 'custom_sound',
},
});
}
const unsubscribe = messaging().onMessage(async notification => {
sendLocalNotification(notification);
});
notifee.onForegroundEvent(async data => {
const { type, detail } = data;
switch (type) {
case EventType.DISMISSED:
await notifee.cancelNotification(detail.notification.id);
break;
case EventType.PRESS:
handelNotification(
detail.notification.data,
detail.notification.id,
);
break;
}
});
< /code>
7. Запрос разрешения < /h3>
В app.js < /li>
< /ul>
useEffect(() => {
NotifyPermissions();
}, []);
async function NotifyPermissions() {
await messaging().requestPermission();
}
< /code>
Это отлично подходит для меня; Нет необходимости ни в чем другое. < /p>
"dependencies": {
"@notifee/react-native": "^9.1.8",
"@react-native-firebase/app": "18.6.1",
"@react-native-firebase/messaging": "18.6.1",
"react": "18.2.0",
"react-native": "0.74.3",
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... e-backgrou
Мобильная версия