Я пытаюсь настроить push-уведомление на iOS и Android с помощью Firebase/mesaging.
Я выполнил часть настройки, используя googleservice-info и так далее...
Я активировал push-уведомление и обе необходимые нам возможности фонового режима. Я нажал клавишу APN на Firebase для iOS.
Это мой код:
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);
} ...
}
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();
}
package-lock.json
"@react-native-firebase/app": "^18.4.0",
"@react-native-firebase/messaging": "^18.4.0",
и тогда я получаю
ERROR [Error: [messaging/unknown] The operation couldn’t be completed. No APNS token specified before fetching FCM Token]
Я пытаюсь добавить это в 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