我正在使用expo开发应用程序。我想使用expo-notifications在我的应用程序中发送和接收推送通知。 我已经集成了expo-notification,成功地接收到通知,但是没有声音和弹出警报。我总是不得不向下滚动通知面板,然后才能看到通知。 这是我注册通知的代码:
async function registerForPushNotificationsAsync() {
let token;
if (Constants.isDevice) {
const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
let finalStatus = existingStatus;
if (existingStatus !== 'granted') {
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
finalStatus = status;
}
if (finalStatus !== 'granted') {
alert('Failed to get push token for push notification!');
return;
}
token = (await Notifications.getExpoPushTokenAsync()).data;
console.log(token);
} else {
alert('Must use physical device for Push Notifications');
}
if (Platform.OS === 'android') {
Notifications.setNotificationChannelAsync('default', {
name: 'default',
importance: Notifications.AndroidImportance,
vibrationPattern: [0, 250, 250, 250],
lightColor: '#FF231F7C',
});
}
return token;
}
这是我的UseEffect,我在其中注册并监听通知。
useEffect(() => {
_gettingRestaurants();
registerForPushNotificationsAsync().then(token => setExpoPushToken(token));
// This listener is fired whenever a user taps on or interacts with a notification (works when app is foregrounded, backgrounded, or killed)
Notifications.addNotificationReceivedListener((notification)=>{
alert(notification);
});
Notifications.addNotificationResponseReceivedListener((response)=>{
alert(response);
});
}, [isDataFetched])
还有一件事,这些监听器也不起作用。我没有看到来自这两个警报的任何警报。请帮帮我。
谢谢!!!