Как правильно запланировать локальное уведомление в React Native (Expo)?
Реализовал отправку уведомлений в приложении Expo, но работает она не правильно. Вот код:
import { Constants, Notifications } from 'expo';
import * as Permissions from 'expo-permissions';
export default function HomeScreen() {
// Notifications
var isGrantedForNotifications = false;
var askPermissionsForNotifications = async () => {
const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
let finalStatus = existingStatus;
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
finalStatus = status;
if(finalStatus == "granted") return true;
else return false;
};
const reminderNotification = {
title: 'Test',
body: 'This is test notification for reminder.',
ios: {
sound: true
},
android:
{
sound: true,
priority: 'high',
sticky: true,
vibrate: true
}
};
var scheduleNotification = async () => {
let isFixed = false;
if(isGrantedForNotifications === false) isFixed = askPermissionsForNotifications();
if(isFixed === true) isGrantedForNotifications = true;
let currentTime = new Date();
currentTime.setSeconds(currentTime.getSeconds() + 10);
const schedulingOptions = {
time: currentTime,
};
Notifications.scheduleLocalNotificationAsync(reminderNotification, schedulingOptions);
};
return (
<Button title={"Notify immediately"} onPress={sendNotification}></Button>
<Button title={"Notify in next 10 seconds"} onPress={scheduleNotification}></Button>
);
};
После тестирования на Android, выяснилось, что там всё нормально: уведомление показывается и при нажатии на кнопку мгновенного его вызова, и при запланированном запуске, но без звука, хотя в свойствах прописано sound: true. На iOS же уведомление показываются только, если приложение свёрнуто. Можно ли как-нибудь сделать вывод уведомления в самом приложении на iOS?