Ich habe den Einrichtungsteil mit googleservice-info usw. befolgt ...
Ich habe die Push-Benachrichtigung und beide Hintergrundmodusfunktionen aktiviert, die wir benötigen. Ich habe den APN-Schlüssel auf Firebase für iOS gedrückt.
Das ist mein Code:
Code: Select all
index.js
Code: Select all
import { getMessaging } from '@react-native-firebase/messaging';
import firebase from '@react-native-firebase/app';
const credentials = {...}
if (!firebase.apps.length) {
firebase.initializeApp(credentials).then((app) => {
getMessaging(firebase).setBackgroundMessageHandler(async remoteMessage => {
console.log('Message handled in the background!', remoteMessage);
});
})
}
Code: Select all
const getFcmToken = async () => {
console.log("trying to get")
try {
const newFcmToken = await messaging().getToken() // HERE
console.log('newFcmToken');
console.log(newFcmToken);
} ...
}
Code: Select all
const authStatus = await messaging().requestPermission();
if (!messaging().isDeviceRegisteredForRemoteMessages) {
await messaging().registerDeviceForRemoteMessages();
}
const enabled =
authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authStatus === messaging.AuthorizationStatus.PROVISIONAL;
if (enabled) {
console.log('Authorization status:', authStatus);
await getFcmToken();
}
Code: Select all
package-lock.json
Code: Select all
"@react-native-firebase/app": "^18.4.0",
"@react-native-firebase/messaging": "^18.4.0",
Code: Select all
ERROR [Error: [messaging/unknown] The operation couldn’t be completed. No APNS token specified before fetching FCM Token]
Code: Select all
FirebaseAppDelegateProxyEnabled
GCMessagingSenderId
...
```
At some point I remembered succeeding having a token, I have one on the firebase dashboard.