React-native-push-notification: onRegister is never called (on device)

Created on 17 Mar 2018  ·  32Comments  ·  Source: zo0r/react-native-push-notification

I've spent countless hours trying to debug this, and although PushNotification.configure({..}) is called, the onRegister callback never fires — I've set requestPermissions to true, and even tried calling it manually; it still never fires. Currently I'm running it on an ASUS Zenfone Android 7.0 device, but just cant seem to get the token

Most helpful comment

@Amnesthesia To test, I found using PushNotificationIOS.addEventListener('registrationError', console.log) EXTREMELY useful, it showed me the exact reason of why it was failing.

All 32 comments

Same here, trying on iPhone7. Local notifications work.

@Amnesthesia To test, I found using PushNotificationIOS.addEventListener('registrationError', console.log) EXTREMELY useful, it showed me the exact reason of why it was failing.

same problem

so any solution? after a days of efforts, im thinking it was a total waste of time to go for this half documented project altogether. This method never gets called, so cant get token - how will I get remote push working?!!

Same here! Android never working onRegister callback, anyone??

same here, samsung A3.

Ok guys, ive solved this. Here is my post, check it out:
https://github.com/zo0r/react-native-push-notification/issues/697

Guys, for iOS you should do this:
https://stackoverflow.com/questions/27324020/no-valid-aps-environment-entitlement-string-found-for-application-on-app-store

If you already done setup tutorial for this library, you might be forgotten to setup Push Notifications in Capabilities panel in XCode.

If nothing happend, try to catch error using this code (for iOS only):

PushNotificationIOS.addEventListener('registrationError', (e) => { alert(JSON.stringify(e)) });

This fixed it for me -- I had to go into XCode > Project > Capabilities and turn on Push Notifications. Then the onRegister() callback started firing.

@Amnesthesia + 1 Android onRegister is never called. I got iOS working, got the token, and saved to the back-end where I send remote push notifications. But for Android, onRegister is never called with the same code in configure. So, can't get the token. I've spent hours on this too.

I'm also having trouble with Android onRegister. Tried everything in AndroidManifest.xml. Any ideas?!

Ok guys, ive solved this. Here is my post, check it out:

697

it's ok for android, thank you very much!

@dgurns thanks that solved it for me too.. wasted some good hours on that...

I was having the same problem. For android add senderID: "123**" (sender key value) which are numeric value. It solved my problem. (For GCM its project number).

@lequangtuananh I'm facing this same problem on Android, but I'm not using Firebase. Does your solution still apply to my scenario?

I was facing this issue for several hours on my IOS device locally. Turns out the fix was to simply restart my XCode & rebuild 🤷‍♂️

@Dallas62 hi, i'm not getting device token on ios, can you please help me out, i'm using latest version ^4.0.0. Thanks

@ZishanK Test first solutions in this issues.
This library is a wrapper of another iOS library (react-native-community/push-notification-ios), if there is any issue, it's not here 😉

Also,
https://github.com/zo0r/react-native-push-notification#usage
onRegistrationError has been added for the case there is an error on registration.

this is also not triggering, don't what's the issue there.

Maybe share .configure ?

PushNotification.configure({
onRegister: function (token) {
console.log("TOKEN:", token);
},
// (required) Called when a remote or local notification is opened or received
onNotification: function(notification) {
console.log("NOTIFICATION:", notification);
// required on iOS only
notification.finish(PushNotificationIOS.FetchResult.NoData);
},
// Android only
senderID: "XXXXXX", //This is hidden to protect my own project
// iOS only
permissions: {
alert: true,
badge: true,
sound: true
},
popInitialNotification: true,
requestPermissions: true
})

There is no onRegistrationError in your code.
also senderID is not needed anymore.

onRegistrationError also not triggering, only trigger when i use simulator. when i run app on device, both onRegister and onRegistrationError not trigger.

Did you allowed notification?
And also configured your application for notification?

yes, everything is done but no luck.

Same here. I think there is some bugs in the wrapper or missing documentation.

Hi @ZishanK, @student-t

Is it for Android ?
Did you try to set up firebase on the example project ?

This could be a network issue, some times I have to turn off the Wifi of my computer (when using simulator) to kill pending connections, then turning it on make this work again...

Wait is it for iOS or Android ?
For iOS you should provide you your AppDelegate, without it we can't help.
I'm able to get token on iOS, this looks like a configuration issue.

Hi @student-t
Your last comment disappeared but yes you need to setup your iOS app to receive notification.
For local notification, nothing to do, for remote you need to setup APN

hi @Dallas62 @student-t , its for ios and in my case i've setup each and everything but not getting call onRegister.

Just found something really interesting inside the apple docs!

https://developer.apple.com/library/archive/technotes/tn2265/_index.html#//apple_ref/doc/uid/DTS40010376-CH1-TNTAG21

No Delegate Callbacks
When the first push-capable app is installed, iOS or OS X attempts to establish a persistent network connection to the push service that will be shared by all push-capable apps on the system. If neither delegate callback application:didRegisterForRemoteNotificationsWithDeviceToken: nor application:didFailToRegisterForRemoteNotificationsWithError: is called, that means that this connection has not yet been established.

So after adding a sim card into my testing device – which was already connected by wifi – it seems to ping the apple services again and it start working.
So my issue resolved by putting SIM card to the phone and it starts working. thanks for your help. especially @Dallas62 thanks a lot, you are really helpful.

Was this page helpful?
0 / 5 - 0 ratings