I've set up all the instructions mentioned on this package and PushNotificationIOS by react native. https://facebook.github.io/react-native/docs/pushnotificationios.html
onRegister gets called and token is generated successfully but I couldn't get any notifications on my iPhone sent from firebase.
It's working fine on Android.
@aryalprakash any progress on this issue??
+1
+1
I figured out what was happening, when your onregister gets called it generates a device token and not an FCM token for iOS but generates FCM token for Android. So that's why you could receive notifications on Android and not iOS since Firebase sends notifications using the devices FCM token but not the device token.
What I did was set Firebase for iOS following this. And then I created a RN bridge that sends the FCM token received from the Firebase setup to the front-end, I accessed it using NativeModules and then I could get the FCM token to the servers and everything works fine.
@justmesam You right. Can you share IOS code. I don't know Objective-C.
For now just implemented this fix:
import firebase from 'react-native-firebase';
import { Platform } from 'react-native';
const onRegister = async (token) => {
const deviceToken = Platform.OS === 'ios' ? await firebase.messaging().getToken() : token.token;
console.log(deviceToken );
};
and
PushNotification.configure({
// (optional) Called when Token is generated (iOS and Android)
onRegister: onRegister.bind(this),
.....
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.
Most helpful comment
I figured out what was happening, when your
onregistergets called it generates a device token and not an FCM token for iOS but generates FCM token for Android. So that's why you could receive notifications on Android and not iOS since Firebase sends notifications using the devices FCM token but not the device token.What I did was set Firebase for iOS following this. And then I created a RN bridge that sends the FCM token received from the Firebase setup to the front-end, I accessed it using NativeModules and then I could get the FCM token to the servers and everything works fine.