react-native-push-notification: onRegister is not being called
Hi there,
I am using react-native 0.30.0 and react-native-push-notification 2.0.2 and an Android device and have set up everything like in the README but when I call
var PushNotification = require('react-native-push-notification');
PushNotification.configure({
onRegister: function(token) {
console.log( 'TOKEN:', token );
},
onNotification: function(notification) {
console.log( 'NOTIFICATION:', notification );
},
senderID: "MY GCM SENDER ID",
});
nothing happens (neither in logcat nor anything else).
Do you know what the issue may be or how to debug this?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 1
- Comments: 18
Hi i am using ReactNative 0.31 and com.google.android.gms:play-services-gcm:8.1.0 with a valid project id but the onRegister callback is not triggering neither on the real device nor on emulator. This is what i have so far
Am i missing some thing ? BTW I am upgrading the application from 0.25 to 0.31 and it is working in the old application.
+1
The local notification is called, but neither my connected device nor the virtual device calls
onRegister. I have read the troubleshooting section - that’s why I use a connected device now. Do I need to mention that I changed the sender ID for public display?Calling
requestPermissionsnot only seems redundant but it doesn’t fix anything, but I did try that.What fixes this?
"react-native-push-notification": "^3.1.9",The fact that the calls are made in
componentDidMounthas no effect.Yes, it works on Android with RN 0.39.2. I was lost about what value should I put as senderId. Because I thought that device token should be same independent from the senderId which is obviously a wrong assupmtion. And also instead of GCM you should use FirebaseCM to obtain a senderId nowadays.
Ok disregard that. Apparently a token cannot be granted until your application’s root component has been constructed. @sajjad26 @BigPun86 Make sure you are calling
PushNotification.requestPermissions(YOUR_SENDER_ID)after that. You’ll need to pass through the sender id even if you set it inPushNotification.configure.Mi example worked when I actually added the GCM SENDER ID (although the docs say is optional). Also you should test on a real device not an emulator. You can get your Project ID at https://console.cloud.google.com