mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
issue #63: fix for iphone push notifiications, thanks @youngiphone & @Dinobali for reporting
This commit is contained in:
parent
607111071b
commit
da5b12d0e7
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user