Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔥v5.6.0: Push Notifications not working on RN60.6 #3188

Closed
2 tasks
jvgeee opened this issue Feb 10, 2020 · 6 comments
Closed
2 tasks

🔥v5.6.0: Push Notifications not working on RN60.6 #3188

jvgeee opened this issue Feb 10, 2020 · 6 comments

Comments

@jvgeee
Copy link

jvgeee commented Feb 10, 2020

Issue

After a few full days of banging my head against a wall following Push notifications aren't working for me following the docs as well as Invertase's recommended Medium article, I cannot for the life of me get push notifications to work.


Project Files

I'm really there's something simply wrong with my setup that I've managed to overlook! I can get an FCM token in-app

android/build.gradle

dependencies {
      classpath 'com.android.tools.build:gradle:3.5.3'
      classpath 'com.google.gms:google-services:4.0.0'
  }

android/app/build.gradle

dependancies{
    // Other stuff above
    implementation "com.google.android.gms:play-services-base:17.0.0"
    implementation "com.google.firebase:firebase-core:17.0.1"
    implementation "com.google.firebase:firebase-config:17.0.0"
    implementation "com.google.firebase:firebase-messaging:19.0.1"

}
apply plugin: 'com.google.gms.google-services'

androidManifest.xml

     <service 
        android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />
    <service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
      <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
      </intent-filter>
    </service>

MainApplication.java

import io.invertase.firebase.analytics.RNFirebaseAnalyticsPackage;
import io.invertase.firebase.messaging.RNFirebaseMessagingPackage;
import io.invertase.firebase.notifications.RNFirebaseNotificationsPackage;
import io.invertase.firebase.config.RNFirebaseRemoteConfigPackage;

// ... later on

      packages.add(new RNFirebaseAnalyticsPackage());
      packages.add(new RNFirebaseMessagingPackage());
      packages.add(new RNFirebaseNotificationsPackage());
      packages.add(new RNFirebaseRemoteConfigPackage());

package.json:

 "react-native": "0.60.6",
 "react-native-firebase": "~5.6.0"

Have you converted to AndroidX?

  • my application is an AndroidX application?
  • I am using android/gradle.settings jetifier=true for Android compatibility?
  • [ x ] I am using the NPM package jetifier for react-native compatibility?

Final Notes

In JS, using firebase.messaging().getToken();, I'm able to successfully get an FCM token.

I'm going into our project in Firebase and sending a test notification to this device (emulated Pixel 2)

image

The notification does not appear on my device.

So:

  1. I'm able to generate an FCM token and correctly access it
  2. No errors in Android Studio or during build
  3. No errors in my JS console
  4. I'm not able to RECEIVE the push notification. Nothing happens. I've tried looking in the logs in android studio, but I'm not seeing nothing (and the logs seem to stop running when my app is closed/in the background)

Prior to upgrading React Native (from 59) and RNFirebase, this worked fine. Not sure what I'm doing wrong here! Any tips?

@mikehardy
Copy link
Collaborator

Please don't pick and choose which parts of the files you post, we need the whole files. We also need to know what APIs you're trying against Android.
A minimal reproduction (like, a complete App.js or index.js) would be very useful as well to make sure you're requesting permissions / registering for things at the javascript level.

@jvgeee
Copy link
Author

jvgeee commented Feb 10, 2020

// Edited to remove potentially sensitive info

@mikehardy
Copy link
Collaborator

Try de-integrating your splash activity as a temporary test. Sometimes those cause problems (crazycodeboy/react-native-splash-screen#289 (comment))

You didn't post package.json so I'm not sure which splash screen you're using but the one I linked to has issues if not integrated carefully

What does raw adb logcat tell you?

@jvgeee
Copy link
Author

jvgeee commented Feb 10, 2020

// Edited to remove potentially sensitive info (it's just a package.json)

@mikehardy
Copy link
Collaborator

well, usually I learn more or the same as I end up teaching/helping so it helps me too up to a point ;-). But this is very odd.

Honestly just to make sure you aren't going crazy (I mean, you're doubting you're even sending a push notification correctly at this point...which is natural but also calls everything into question) I would make a throwaway app with just the minimum integration required for messaging and prove you can make it work. Then I would sort of hack-and-slash a "bisect" of functionality between the minimal "it works" throwaway and your full app. First attempt to integrate about half the things you've got in AndroidManifest and see if it still works then focus on each smaller half until you arrive. It is kind of brutal to do but also works.

For a minimal starter you can begin with this (it'll be react-native 0.61.5 + react-native v5): https://github.com/mikehardy/rnfbdemo/blob/master/make-demo.sh

@jvgeee
Copy link
Author

jvgeee commented Feb 11, 2020

I'm gonna sound like an absolute nufty, but it turned out that after AAAAAAAAALL of this (I created a new blank from scratch using the script above and basically rebuilt EVERYTHING, it turned out that I had had everything configured correctly (just as per the docs) from the start, and my actual issue was that I was sending the test push notification from the wrong bloody Firebase project!

I've edited out the files I posted above just in case there's some sensitive info in there, but all it was was everything in the RNFirebase v5.x.x Docs, nothing fancy!

On a nicer note, now I have an android / ios project that is completely fresh and doesn't have 3 year old code form React Native's infancy sticking around that no one here remembers how to use!

Cheers for your help Mike!

@jvgeee jvgeee closed this as completed Feb 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants