react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

iOS push notification not receive when app in background.

Open Mamdouh-Symbyo opened this issue 8 years ago • 7 comments

notification is received when app in foreground by onMessage() this function

Firebase
 .messaging()
 .onMessage(message => {
      console.log('message received', message);
  });

but it not received when app in on background.

firebase libraries versions: Using Firebase (4.0.4) Using FirebaseAnalytics (4.0.2) Using FirebaseAuth (4.0.0) Using FirebaseCore (4.0.4) Using FirebaseInstanceID (2.0.8) Using FirebaseMessaging (2.0.0)

iOS device version: 11.2.2

Mamdouh-Symbyo avatar Jan 09 '18 10:01 Mamdouh-Symbyo

@Mamdouh-Symbyo FCM support is a little shaky at the moment and we're planning on overhauling it in our next major release. We've had lots of similar issues reported that we're closing off until we properly fix the functionality.

Keep track of this for updates: https://github.com/invertase/react-native-firebase/issues/595

chrisbianca avatar Jan 12 '18 09:01 chrisbianca

@Mamdouh-Symbyo You need to upload your certificate to the firebase messaging settings. Then enable push messages in xcode and it will work even when running the app in background and its closed.

digitaledge avatar Jan 13 '18 23:01 digitaledge

@Mamdouh-Symbyo where do I upload the certificates?

hegelstad avatar Jan 31 '18 01:01 hegelstad

its working with me now, what i did: -generate APNs key. https://firebase.google.com/docs/cloud-messaging/ios/certs -upload APNs key to firebase project. in firebase project => settings => cloud messaging => iOS app configuration => APNs Authentication Key -also Make sure your application requested notification permissions upon first launch.

  // requests permissions from the user
  FCM.requestPermissions();
  FCM.getToken()

thank you @chrisbianca

Mamdouh-Symbyo avatar Feb 26 '18 14:02 Mamdouh-Symbyo

@hegelstad i upload APNs key to firebase project => settings => cloud messaging => iOS app configuration => APNs Authentication Key

Mamdouh-Symbyo avatar Feb 26 '18 15:02 Mamdouh-Symbyo

@Mamdouh-Symbyo i have already uploaded the .p8 file in the firebase project setting its not working when app in background,

should i upload the .p12 file ???

yusuf987 avatar Apr 13 '19 15:04 yusuf987

@yusuf987 When you upload a p8 key and it doesn't work meaning there's an issue with your p8 file.

Try using below code in Postman or Terminal and see what it responds

curl -X POST \ https://fcm.googleapis.com/fcm/send \ -H 'Authorization: key=REPLACE_FCM_SERVER_KEY_HERE' \ -H 'Cache-Control: no-cache' \ -H 'Content-Type: application/json' \ -d '{ "to" : "IOS_DEVICE_TOKEN_HERE", "notification" : { "body" : "Push test", "title" : "Push test", "content_available" : true, "priority" : "high" } }'

I was having the same issue, I finally resolved it by Re-generating new APN Key auth file and Re-uploading to FCM.

What was the issue in my case:

  • I had an old Key auth file, which was generated 2 months ago. I started a new App in the same Apple dev account and used the same old p8 file and It didn't work in New app.
  • I had to Generate a new one and upload to Firebase project to make it work.

Other possible issues:

  • Adding invalid Team ID

krunalp1993 avatar Jun 24 '19 10:06 krunalp1993