Skip to content

Commit

Permalink
issue #63: fix for iphone push notifiications, thanks @youngiphone & @…
Browse files Browse the repository at this point in the history
…Dinobali for reporting
  • Loading branch information
rolandosborne committed Jan 16, 2024
1 parent 6071110 commit da5b12d
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions app/mobile/src/context/useAppContext.hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@ export function useAppContext() {
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(() => {

// select the unified token if available
Expand All @@ -54,11 +74,7 @@ export function useAppContext() {

(async () => {
try {
const token = await messaging().getToken();
if (!deviceToken.current) {
deviceToken.current = token;
pushType.current = "fcm";
}
await setFcmToken();
}
catch (err) {
console.log(err);
Expand Down

0 comments on commit da5b12d

Please sign in to comment.