Я пытаюсь настроить Push-уведомление на iOS и Android, используя Firebase /Mesaging. Я нажал клавишу APN на Firebase для iOS. < /P>
Это мой код: < /p>
index.js
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);
});
})
}
Затем в моем app.tsx
const getFcmToken = async () => {
console.log("trying to get")
try {
const newFcmToken = await messaging().getToken() // HERE
console.log('newFcmToken');
console.log(newFcmToken);
} ...
}
< /code>
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>
package-lock.json
"@react-native-firebase/app": "^18.4.0",
"@react-native-firebase/messaging": "^18.4.0",
< /code>
and then I get a
ERROR [Error: [messaging/unknown] The operation couldn’t be completed. No APNS token specified before fetching FCM Token]
< /code>
I try to add this in the info.plist
FirebaseAppDelegateProxyEnabled
GCMessagingSenderId
...
```
At some point I remembered succeeding having a token, I have one on the firebase dashboard.
Подробнее здесь: https://stackoverflow.com/questions/771 ... n-t-be-com