我尝试使用react native base messaging和react native push notifications library获取Android设备令牌来发送推送通知:
我在AndroidManifest.xml中添加了配置:
...
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<!-- < Only if you are using GCM or localNotificationSchedule() > -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission
android:name="${applicationId}.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
<!-- < Only if you are using GCM or localNotificationSchedule() > -->
...
在我的App.js
// ----- COMPONENT DID MOUNT ---- //
async componentDidMount() {
// ====================================================== //
// ====================================================== //
// ====================================================== //
const granted = messaging().requestPermission();
if (granted) {
console.log('User granted messaging permissions!');
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
firebase
.messaging()
.getToken()
.then((fcmToken) => {
if (fcmToken) {
// user has a device token
console.log('-------- FCM TOKEN -------');
console.log(fcmToken);
console.log(JSON.stringify(fcmToken));
this._setItem(fcmToken);
} else {
// user doesn't have a device token yet
console.log('error');
}
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
} else {
console.log('User declined messaging permissions :(');
}
// ====================================================== //
// ====================================================== //
// ====================================================== //
}
// ----- FIN COMPONENT DID MOUNT ---- //
我得到了:
可能的未处理Promise拒绝(id:0):
错误:[消息传递/未知] FIS_AUTH_ERROR
NativeFirebaseError:[消息传递/未知] FIS_AUTH_ERROR
2条答案
按热度按时间djmepvbi1#
在Google Cloud Console中,确保google-services.json中的API密钥包含以下权限:
w3nuxt5m2#
我通过再次下载google-services.json文件并将其替换为旧文件来修复它。