wix / react-native-notifications

React Native Notifications
MIT License
3.25k stars 764 forks source link

registerRemoteNotificationsRegistered not triggered on Android #961

Closed Pietro-Putelli closed 1 year ago

Pietro-Putelli commented 1 year ago

I have installed the library following all the steps in the documentaiton, created the app on firebase using the SHA-1 from the project (generating using gradle), downloaded the google-services.json file and add it under the folder app.

Here's the code:

  useEffect(() => {
    Notifications.events().registerRemoteNotificationsRegistered(
      ({ deviceToken }) => {}
    );

    Notifications.events().registerRemoteNotificationsRegistrationFailed(
      (event) => {
        console.error(event);
      }
    );
  }, []);

But the registerRemoteNotificationsRegistered is not triggered, neither registerRemoteNotificationsRegistrationFailed.

The only step I'm missing from the guide is the four (https://wix.github.io/react-native-notifications/docs/installation-android) because apply plugin: 'com.google.gms.google-services' cause the build to fail.

Some problems were found with the configuration of task ':react-native-notifications:processReactNative60DebugGoogleServices' (type 'GoogleServicesTask').
  - In plugin 'com.google.gms.google-services' type 'com.google.gms.googleservices.GoogleServicesTask' field 'intermediateDir' without corresponding getter has been annotated with @OutputDirectory.

    Reason: Annotations on fields are only used if there's a corresponding getter for the field.

    Possible solutions:
      1. Add a getter for field 'intermediateDir'.
      2. Remove the annotations on 'intermediateDir'.

Here is the version: react-native: 0.71.4 => 0.71.4

dleavittpmc commented 1 year ago

In your top build.gradle instead of classpath 'com.google.gms:google-services:4.0.0' Try this: classpath ("com.google.gms:google-services:4.3.15")

It's what the docs in firebase say to do, and it doesnt cause the app to crash

tamlyn commented 1 year ago

Yep I also had this issue and fixed it as above. There's also a PR open to update the docs: #953.

This issue can be closed.

jkoutavas commented 1 year ago

I followed all the steps at https://wix.github.io/react-native-notifications/docs/installation-android/ but I can't get registerRemoteNotificationsRegistered() to return a token while running on Android. I'm on react-native 0.71.7. The registration event never occurs.

      Notifications.registerRemoteNotifications()

        Notifications.events().registerRemoteNotificationsRegistered(event => {
            // TODO: Send the token to my server so it could send back push notifications...
            console.log('Device Token Received', event.deviceToken)
        })
        Notifications.events().registerRemoteNotificationsRegistrationFailed(event => {
            console.error(event)
        })

I'm suspecting that Notifications.registerRemoteNotifications() is busted. How to debug it?

jkoutavas commented 1 year ago

Yep I also had this issue and fixed it as above. There's also a PR open to update the docs: #953.

This issue can be closed.

@tamlyn As seen in my post, I'm able to build fine, but am not getting back a token on Android. You wouldn't happen to have an example of your working Android app kicking around anywhere on GitHub that I could inspect?

samonov22 commented 1 year ago

@jkoutavas, instead of adding this lines to ./android/app/build.gradle:

dependencies {
    ...
    implementation project(':react-native-notifications')
    implementation 'com.google.firebase:firebase-core:16.0.0'
} 

as said in docs (https://wix.github.io/react-native-notifications/docs/installation-android), add this:

dependencies {
    ...
    implementation project(':react-native-notifications')
    implementation platform('com.google.firebase:firebase-bom:32.0.0')
    implementation 'com.google.firebase:firebase-analytics-ktx'
}
skinsapp commented 1 year ago

Any one else still having this issue? I've made both gradle updates recommended here, and I'm still not receiving the device token.

My usage works perfectly on iOS, so I'm thinking there's one final piece of missing configuration for Android.

skinsapp commented 1 year ago

@jkoutavas were you able to get it working?

dleavittpmc commented 1 year ago

I don't think the issues are related, the gradle problems and not receiving the tokens. I didnt have my gradle set up properly but still received tokens. Just had other issues such as the one at the beginning of this post.

Check again, for completeness. Make sure you completed these correctly:

Also, make sure your FCM is set up sorrectly

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

bananer commented 1 year ago

What solved the problem for me was calling registerRemoteNotificationsRegistered before calling registerRemoteNotifications, unlike how the docs suggest.

Using react-native 0.72.3 with the workaround from https://github.com/wix/react-native-notifications/issues/975#issuecomment-1623856736 .

android/build.gradle contains classpath("com.google.gms:google-services:4.3.15")

android/app/build.gradle contains:

    implementation project(':react-native-notifications')

    implementation platform('com.google.firebase:firebase-bom:32.2.0')
    implementation "com.google.firebase:firebase-messaging"
stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] commented 1 year ago

The issue has been closed for inactivity.