issue #63: fix for iphone push notifiications, thanks @youngiphone & @Dinobali for reporting

This commit is contained in:
balzack 2024-01-15 21:29:54 -08:00
parent 607111071b
commit da5b12d0e7

View File

@ -44,6 +44,26 @@ export function useAppContext() {
setState((s) => ({ ...s, ...value })) setState((s) => ({ ...s, ...value }))
} }
const setFcmToken = async () => {
if (!deviceToken.current) {
try {
const token = await messaging().getToken();
if (!token) {
throw new Error('null push token');
}
deviceToken.current = token;
pushType.current = "fcm";
}
catch (err) {
console.log(err);
await new Promise(r => setTimeout(r, 2000));
const token = await messaging().getToken();
deviceToken.current = token;
pushType.current = "fcm";
}
}
}
useEffect(() => { useEffect(() => {
// select the unified token if available // select the unified token if available
@ -54,11 +74,7 @@ export function useAppContext() {
(async () => { (async () => {
try { try {
const token = await messaging().getToken(); await setFcmToken();
if (!deviceToken.current) {
deviceToken.current = token;
pushType.current = "fcm";
}
} }
catch (err) { catch (err) {
console.log(err); console.log(err);