React-native-push-notification: Token generated but couldn't receive notificatios sent from fcm in iOS only

Created on 30 Apr 2019  路  6Comments  路  Source: zo0r/react-native-push-notification

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.

Stale

Most helpful comment

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.

All 6 comments

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

selimonline picture selimonline  路  3Comments

atteia picture atteia  路  4Comments

cidevant picture cidevant  路  3Comments

cookienawer picture cookienawer  路  3Comments

Kiran0791 picture Kiran0791  路  3Comments