【发布时间】:2021-06-10 20:14:11
【问题描述】:
当用户在特定屏幕中时,如何禁用在我的 Expo 应用中显示通知?
我目前正在设计一个聊天屏幕,我想在用户在其中时禁用推送通知。
目前,我在 PushNotifications 模块中实现了以下方法:
export function setNotificationHandler(handler) {
ExpoNotifications.setNotificationHandler(handler);
}
export function hidePushNotifications() {
setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: false,
shouldPlaySound: false,
shouldSetBadge: false,
}),
});
}
export function unhidePushNotifications() {
setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: true,
shouldSetBadge: true,
}),
});
}
在我的聊天屏幕中,在 useEffect 中,我正在做:
useEffect(() => {
// Do not show push notifications when the user is inside this screen
hidePushNotifications();
return () => {
// When unmounted, unhide push notifications
unhidePushNotifications();
};
}, []);
对我来说,这很有意义,因为我在用户进入聊天屏幕时“隐藏”推送通知,并在他离开时“取消隐藏”它们。
但由于某些原因,通知仍显示在聊天屏幕内。为什么?
我该如何解决这个问题?
【问题讨论】:
标签: javascript reactjs react-native push-notification expo