我用firebase设置了通知系统并做出了本机反应。它工作正常,但是当我在应用程序的任何状态(已终止,未处理或后台)收到通知并单击通知时,将我推送到主屏幕。当有人单击通知时,我想进入通知屏幕。怎么可能?
首先,您必须在顶级组件上添加Firebase Notification侦听器。我建议将其放在App.js中。
之后,您必须借助导航道具导航到特定屏幕。如果将侦听器放置在App.js上,则您将无权访问导航道具,因为App.js将返回导航容器。为此,您必须创建一个辅助功能,例如没有导航的导航
例如
export const App = () => {
messaging().setBackgroundMessageHandler(async remoteMessage => {
navigate('Notification'); //navigate to notification screen
});
const unsubscribe = messaging().onMessage(async remoteMessage => {
//generate local notification using your preferred library
//handle navigation
})
return <RootNavigator />;
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句