【发布时间】:2020-11-07 09:51:56
【问题描述】:
我尝试使用 react native base 消息传递和 react native 推送通知库来获取 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 ---- //
我明白了:
可能的未处理承诺拒绝(id:0):
错误:[消息/未知] FIS_AUTH_ERROR
NativeFirebaseError:[消息/未知] FIS_AUTH_ERROR
【问题讨论】:
-
我也面临同样的问题。你能分享一下你是怎么解决的吗?
标签: android react-native push-notification firebase-cloud-messaging token