React-native-push-notification: onRegister callback is never called, both on Android and iOS

Created on 20 Sep 2016  路  21Comments  路  Source: zo0r/react-native-push-notification

Hey there,

It seems like the onRegister callback is never activated. I've tried on both iOS and Android platform.
I have managed to receive a prompt asking for Notifications permissions.

I also followed the stack trace all the way through callNative, which is triggered with a function named "register" and the appropriate callback ( _onRegister ) , it is never fired.

This is how I configure my PushNotification :

componentDidMount() {
    PushNotification.configure({
      // (optional) Called when Token is generated (iOS and Android)
      onRegister: (token) => {
        // ...
      },
      onNotification: (notification) => {
        // ...
      },
      senderID: "< A SENDER ID >",
      popInitialNotification: true,
      requestPermissions: true
    });
  }

I've truncated the code in both onRegister and onNotification, but it triggers a fetch call to a remote API. I've switched the logic to a simple console.error(token) and nothing.

Also, the remote debugger never stops if I put a debugger; at the beginning of onRegister

I am working with the latest version of this package as well as react-native 0.34-rc.0 on iOS 10 and Android 6.0.0

Finally, I did test push notifications for both platforms on PushWatch and it does work.

Most helpful comment

for me problem was that with xcode 8 Push Notification capability was disabled. I enabled it again, and then it worked

All 21 comments

i have the same problem, try config many times and just re-config step to step carefully but nothing happen!.

Same here.
react-native 0.34. Both iOS and Android, same symptoms.

same here

'Nexus 6 - 5.1.1'

"react": "15.3.2",
"react-native": "^0.33.0",

"name": "react-native-push-notification",
"version": "2.1.1",

are you guys testing on a real device ? I think onRegister is never called on emulators

yes, I tested it on real 'Nexus 6 - 5.1.1' device

Yes, I'm building on real phones and tablet. Can't seem to have any devices that registers.

Could you guys post all the relevant code that you are using to register the onRegister event handler?

componentDidMount() { PushNotification.configure({ onRegister: function(token) { console.log( 'TOKEN:', token ); }, onNotification: function(notification) { console.log( 'NOTIFICATION:', notification ); }, senderID: "YOUR GCM SENDER ID", popInitialNotification: true, requestPermissions: true, }); }

for me problem was that with xcode 8 Push Notification capability was disabled. I enabled it again, and then it worked

@leoabacade Can you confirm that the senderId is an actual sender id and "YOUR GCM SENDER ID" in your code as you have put in the sample code. The senderId should be a valid senderId. If it is undefined, you will not receive the register event. Other than that, the code looks correct. If you continue to have this problem, you can start the app via Android Studio and put breakpoints at relevant places and debug it.

thanks for the help, after put in the correct GCM SENDER ID
i finally got the response
TOKEN: Object {token: "_", os: "android"}os: "android"token: "_"proto: Object

Still having this problem.
I inserted correct GCM sender ID, but still nothing, neither IOS or Android

@nicolabortignon are you testing on physical android an iOS devices? Simulators and emulators will not work. Have you carefully followed all of the instructions in the readme? Are you seeing any error messages either when your app starts or when a notification is sent/received? Are you testing remote push notifications or local notifications?

@npomfret I opened a more detail issue here : https://github.com/zo0r/react-native-push-notification/issues/227

Thanks for the support

I'm using a physical Samsung phone, but also am unable to receive a token.:

"project_info": {
"project_number": "1234567890", <- I'm using this for my GCM Sender ID
"firebase_url": "https://xxx.firebaseio.com",
"project_id": "xxx",
"storage_bucket": "xxx.appspot.com"
},

@semiautomatix are you getting any errors? have you linked the project correctly? have you updated the manifest file? Do you see any DEBUG level output in logcat (with no filters) that contains the text RNPushNotification ?

@npomfret I think after much tinkering I though it might be conflicting com.google.android.gms:play-services-gcm:* or the google-services.json file that was included. By removing that line and file it seems to now be functioning.

There was no obvious error or anything in logcat to indicate an error, however :/

Thanks for the quick reply though! 馃憤

Ok, could you let me know the details? I'm thinking of putting together a troubleshooting file, seems that lots of people are having issues with this project. It would be good to get your input.

@npomfret No problem, I think the issue was that I was using the Ignite template, which previously had react-native-push-notification but was removed due to problems. As such I was getting a build error on Android when including

compile ('com.google.android.gms:play-services-gcm:8.1.0') {
    force = true;
}   

in build.gradle:

:app:dexDebug
Unknown source file : UNEXPECTED TOP-LEVEL EXCEPTION:
Unknown source file : com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/iid/MessengerCompat$1;
Unknown source file : at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
Unknown source file : at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
Unknown source file : at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
Unknown source file : at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
Unknown source file : at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
Unknown source file : at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
Unknown source file : at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
Unknown source file : at com.android.dx.command.dexer.Main.run(Main.java:277)
Unknown source file : at com.android.dx.command.dexer.Main.main(Main.java:245)
Unknown source file : at com.android.dx.command.Main.main(Main.java:106)

:app:dexDebug FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:dexDebug'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_92\bin\java.exe'' finished with non-zero exit value 2

The recommendation I found was to replace the line with:

compile ('com.google.android.gms:play-services-gcm:9.0.4') { // not 8.0.1
    force = true;
}   

This was problematic, and most likely doesn't work because of conflicting dependencies. The actual solution was to remove the line entirely.

Please note that the dependency is included elsewhere in the code, and not in the build.gradle file.

As such, I'm not sure how many users would have this problem, if they built the application from scratch.

The removal of the google-services.json file might have been a red herring, as it isn't required anyway.

@semiautomatix you saved me dude, I used the project_id instead of project_number as senderID. Totally wrong.

Thanks @semiautomatix, your recommendation solved my problem.

Just a small note: you probably ment:

compile ('com.google.android.gms:play-services-gcm:9.4.0') { // not 9.0.4
    force = true;
}   
Was this page helpful?
0 / 5 - 0 ratings

Related issues

selimonline picture selimonline  路  3Comments

uendar picture uendar  路  3Comments

NiuQiaoling picture NiuQiaoling  路  3Comments

sungjinoh picture sungjinoh  路  3Comments

ahmadallo1 picture ahmadallo1  路  3Comments