【发布时间】:2020-02-03 12:33:21
【问题描述】:
刚刚升级到 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,我似乎无法从服务器取回令牌。如果我尝试console.log(await getToken()),我不会在控制台中得到任何东西。如果我console.log(FCM().getToken()) 我会在控制台中得到一个承诺。我究竟做错了什么?还是我需要升级到最新版本的 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;
}
}
【问题讨论】:
-
你用的是什么版本的 rnfirebase?
-
我使用的是 5.5.7 版
标签: javascript react-native react-native-firebase