刚刚升级到 react native 0.61.5 和 react native firebase (v5.5.7) getToken()
函数似乎没有运行或者它似乎卡在 await
.
我有这个功能:
async function updatePushNotificationsEnabled(isEnabled: boolean) {
return updateUser({ pushNotificationsEnabled: isEnabled, firebaseId: await getToken() })
}
依次调用:
async function getToken() {
try {
return FCM().getToken();
} catch (error) {
return undefined;
}
}
如果我关注https://rnfirebase.io/docs/v5.x.x/messaging/device-token我似乎无法从服务器取回 token 。如果我尝试 console.log(await getToken())
我在控制台中什么也得不到。如果我 console.log(FCM().getToken())
我会在控制台中得到一个 promise 。我究竟做错了什么?还是我需要升级到最新版本的 React Native firebase?
我还检查了权限,设备上的权限已打开,因此返回 true。
我确实有一个检查权限的功能,但这是在应用程序的早期完成的,而不是在我正在做的事情上完成的。
async function requestPermissionIfNeeded() {
try {
if (await FCM().hasPermission()) {
return true;
}
await FCM().requestPermission();
return await FCM().hasPermission();
} catch (error) {
return false;
}
}
最佳答案
最终在 iOS 上为我们工作的是将 React Native firebase 库更新到 v5.6.0
(因为我们还不能更新到 v6)。
这要求我们根据指南将底层 Podfile Firebase 版本更新到 ~6.13.0
。 pod install
后,getToken
函数似乎又能正常工作了。
关于javascript - react native firebase getToken() 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60039337/