У меня возникла проблема: локальное уведомление не отображается в Android, хотя оно отображается в IOS. Я создал разрешения и проверил оптимизацию батареи, чтобы увидеть, в этом ли проблема. Уведомление издает звук, и в левом верхнем углу появляется небольшой квадрат, который, если я щелкну и перетащу, отобразит локальное уведомление. Сейчас я использую эмулятор и попробовал его на реальном устройстве.
Я вызываю уведомление именно так.
onDisplayNotification('default', 'Default Channel', 'Spotback
Android', 'Local push notification')}
/>
Это компонент Notifee.
import notifee, { AndroidStyle, AuthorizationStatus, Notification } from '@notifee/react-native';
import { Alert } from 'react-native';
export const onDisplayNotification = async (id, name, title, body, smallIcon?) => {
// Request permissions (required for iOS)
await notifee.requestPermission();
const settings = await notifee.getNotificationSettings();
const batteryOptimizationEnabled = await notifee.isBatteryOptimizationEnabled();
if (batteryOptimizationEnabled) {
// 2. ask your users to disable the feature
Alert.alert(
'Restrictions Detected',
'To ensure notifications are delivered, please disable battery optimization for the app.',
[
// 3. launch intent to navigate the user to the appropriate screen
{
text: 'OK, open settings',
onPress: async () => await notifee.openBatteryOptimizationSettings(),
},
{
text: 'Cancel',
onPress: () => console.log('Cancel Pressed'),
style: 'cancel',
},
],
{ cancelable: false }
);
}
if (settings.authorizationStatus == AuthorizationStatus.AUTHORIZED) {
console.log('Notification permissions has been authorized');
} else if (settings.authorizationStatus == AuthorizationStatus.DENIED) {
console.log('Notification permissions has been denied');
}
// }
// Create a channel (required for Android)
const channelId = await notifee.createChannel({
id,
name,
});
await notifee.displayNotification({
title,
body,
android: {
channelId,
smallIcon,
pressAction: {
id,
},
},
});
};
Подробнее здесь: https://stackoverflow.com/questions/735 ... in-android