【发布时间】:2021-03-06 17:15:29
【问题描述】:
我刚刚开始在 Expo 中实现推送通知 - 遵循 expo.io 上的指南。因此,我在 Firebase console and my app.json contains now a reference to the Google service file 中创建了一个 Android 应用程序:
"android": {
"package": "------------",
"googleServicesFile": "./google-services.json",
"useNextNotificationsApi": true,
}
如果我在真正的 android 设备(独立应用程序)上进行测试,我不会通过此函数收到有效令牌:
token = (await Notifications.getExpoPushTokenAsync()).data;
相反,我收到以下错误:
错误:调用本机方法时遇到异常:异常 在执行导出的方法 getDevicePushTokenAsync 时发生 模块 ExpoPushTokenManager:请设置您的项目 ID。一个有效的 需要 Firebase 项目 ID 才能与 Firebase 服务器通信 API:它通过 Google 识别您的项目。”
我想这与我的项目设置方式有关。我还遵循了 setup firebase 的 Expo 指南(例如用于电话身份验证),因此在 Firebase 控制台中创建了一个 Web 应用程序。在我的应用程序中,我使用我的网络应用程序配置初始化 Firebase 网络应用程序,如下所示:
const FIREBASE_CONFIG: IFirebaseOptions = {
apiKey: '--------',
authDomain: --------.firebaseapp.com',
databaseURL: 'https://--------.firebaseio.com',
projectId: '--------',
storageBucket: '--------.appspot.com',
messagingSenderId: '--------',
appId: '--------',
measurementId: '',
trackingId: '',
};
firebase.initializeApp(FIREBASE_CONFIG);
FIREBASE_CONFIG(用于我的 Firebase Web 应用)以及 google-services.json(用于我的 Firebase Android 应用)具有正确的项目 ID。我需要以某种方式初始化 Firebase Android 应用吗?
我正在使用 Expo SDK 40.0.1。
【问题讨论】:
标签: firebase react-native expo