我想从expo获取一个firebase令牌,并且必须将该令牌发送到node js,使用它我必须发送推送通知。 每当我运行以下代码时,它都会显示未处理的承诺拒绝:参考错误:找不到变量:自我
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import * as firebase from 'firebase';
import '@firebase/messaging';
export default class App extends React.Component {
async componentDidMount(){
const config = {
apiKey: "xxxx",
authDomain: "xxxx",
databaseURL: "xxxx",
projectId: "xxx",
storageBucket: "xxxx",
messagingSenderId: "xxx",
debug: true
};
firebase.initializeApp(config);
firebase.messaging().getToken()
.then(fcmToken => {
if (fcmToken) {
// user has a device token
console.log("check for tokens",fcmToken)
} else {
console.log("err")
// user doesn't have a device token yet
}
});
}
render() {
return (
<Text>Open up App.js to start working on your app!</Text>
);
}
}