- Прослушивать уведомления, которые приходят в виде событий.
- это также должно происходить, когда приложение работает в фоновом режиме.
- есть ли способ узнать, работает ли мое приложение и фиксирует ли оно события в фон
Я использовал что-то под названием BackgroundService, и реализация примерно такая.
onst fetchNewNotifications = async i => {
console.log('run task here');
await BackgroundService.updateNotification({
taskDesc: 'Checking for new notifications ' + i,
});
};
const headlessNotificationListener = async ({notification}) => {
console.log('notification------>', notification);
};
function App() {
useEffect(() => {
AppRegistry.registerHeadlessTask(
RNAndroidNotificationListenerHeadlessJsName,
() => headlessNotificationListener,
);
const startBackgroundService = async () => {
await BackgroundService.start(task, options);
// Uncomment if you need to update notification details
// await BackgroundService.updateNotification({
// taskDesc: 'Checking for new notifications',
// });
};
startBackgroundService();
// Cleanup is not necessary since we don't want to stop the background task
// return () => {
// BackgroundService.stop();
// };
}, []);
Подробнее здесь: https://stackoverflow.com/questions/785 ... background