Open samaneh-kamalian opened 4 years ago
Hi @samaneh-kamalian You can use: https://github.com/react-native-community/push-notification-ios#addeventlistener
PushNotificationIOS.addEventListener('registrationError', handler);
Regards,
I will add onRegistrationError
in .configure
in the next release.
PushNotificationIOS.addEventListener('registrationError', handler);
thanks for your reply. I used react-native-push-notification for Android. PushNotificationIOS is for IOS! How can use it for android?!
Hi, As far as I now, there is not registrationError in Firebase for Android.
For a registration process I need FCM token. react-native-push-notification works in special way. configure method must call out of components life cycle, so I call it in index.js. So when internet connection of mobile is off and user open my app, it can not get FCM token and I dont know how get fcm token when internet connection turn on! what function I must use?
Hi,
Firebase doesn't provide such event in there SDK.
If you want to retry the token generation, you can use PushNotification.requestPermissions()
.
Also, the current implementation of Firebase for Android triggered onRegister
is triggered when a new token is generated.
https://firebase.google.com/docs/cloud-messaging/android/client#monitor-token-generation
Thanks for your reply. I have two problems: 1- as source code said :
requestPermissions(
permissions?: Array<"alert" | "badge" | "sound">
): Promise<PushNotificationPermissions>;
so this function return Promise but when use PushNotification.requestPermissions().then((token)=>{}) it returns error: TypeError: undefined is not an object( evaluating '_reactNativePushNotification.default.requestPermissions().then') .
2-when I test my app on android10, even if internet connection is on, onRegister does not call. I must colse and open my app several time until onRegister called. I do not have this problem on android 6 and 8.
For the first issue, this is because this function doesn’t return a Promise.
For the second one, this is a Firebase issue: https://stackoverflow.com/questions/37964737/firebase-cloud-messaging-no-token-and-strange-notification-behavior
Hey @Dallas62, are you saying the type definition for requestPermissions is wrong? Presumably only in android land as this works fine on iOS
Hi @mildfuzz This repository doesn't supply any type definitions. If the external repository with type definition is wrong, feel free to find it and fix it.
Actually, there is no Promise returned on Android since there is no "permissions" for notifications on Android. If you think it's not the right way, PR are welcome 😉
Regards,
Okay, thanks 😊 just wanted to be clear that I had understood correctly.
how can handle errors in registration?