【发布时间】:2020-11-10 13:41:23
【问题描述】:
我正在使用 expo 开发一个应用程序。我想使用 expo-notifications 在我的应用程序中发送和接收推送通知。 我已经集成了博览会通知,并且我成功地收到了通知,但没有声音和弹出警报。我总是必须向下滚动通知面板,然后才能看到通知。 这是我注册通知的代码
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])
还有一件事,这些监听器也不起作用。我没有从这两个警报中看到任何警报。请帮帮我。
谢谢!!!
【问题讨论】:
标签: android firebase react-native push-notification expo