該賞金過期3天。回答這個問題有資格獲得 50聲望獎勵。 Alvin Stefanus想引起對這個問題的更多關注。
所以我設定了我的推送通知處理程式:
export function useInitializePushNotification() {
const nav = useHistory();
useEffect(() => {
PushNotifications.removeAllListeners().then(() => {
....
// Method called when tapping on a notification
PushNotifications.addListener('pushNotificationActionPerformed',
(notification: ActionPerformed) => {
let data = notification.notification.data;
let url = `/application?applicationId=${data.applicationId}&app=${data.applicationName}&chatRoomId=${data.chatRoomId}&chatRoomName=${data.chatRoomName}&displayChat=true`.replace(/ /g, '-');
nav.push(url);
}
);
});
return () => {
PushNotifications.removeAllListeners();
}
}, [nav]);
}
從我的App.tsx:
const App: React.FC = () => {
const dispatch = useAppDispatch();
const { setAuth } = useAuth(dispatch);
const [initialized, setInitialized] = useState(false);
useInitializePushNotification();
....
nav.push(url)正在更改我的網址,但路由不起作用。即使導航更改后頁面也不會更改。僅當我從FCM開啟background模式點擊通知時才會發生這種情況,nav.push()如果我的應用程式處于foreground.
我怎樣才能解決這個問題?
uj5u.com熱心網友回復:
經過一番掙扎,我終于找到了解決方案。我Redux用來正確導航它。
在我的pushNotificationActionPerformed活動中:
PushNotifications.addListener('pushNotificationActionPerformed',
(notification: ActionPerformed) => {
let data = notification.notification.data;
let url = `/owner/support?id=${data.chatRoomId}&name=${data.chatRoomName}`;
dispatch(setNeedNavigateTo(url));
}
);
我發送一個 url 以在App.tsx.
這是我的App.tsx:
const needNavigateTo = useAppSelector((state) => state.support.needNavigateTo);
const nav = useHistory();
useEffect(() => {
if (nav && needNavigateTo) {
nav.push(needNavigateTo); //this works
setNeedNavigateTo(undefined); //set the url to undefined (resetting)
}
}, [nav, needNavigateTo]);
這個解決方案對于那些不使用 的人來說并不理想Redux,但這是我找到作業的唯一方法。我不確定這個解決方案是否適用于context.
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/388412.html
