1 回答

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超4個贊
getFcmToken在實(shí)際使用之前聲明。
// declare getFcmToken first
const getFcmToken = async () => {
const fcmToken = await messaging().getToken();
if (fcmToken) {
console.log(fcmToken);
console.log("Your Firebase Token is:", fcmToken);
} else {
console.log("Failed", "No Token Recived");
}
};
// then use it
const authStatus = await messaging().requestPermission();
const enabled =
authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authStatus === messaging.AuthorizationStatus.PROVISIONAL;
if (enabled) {
getFcmToken();
console.log('Authorization status:', authStatus);
}
};
添加回答
舉報(bào)