react-native-fcm
react-native-fcm copied to clipboard
Device Token is null in some devices?
Is it possible that device_token can be null in some android devices?
u need to ask for push permission on android M
@sibelius can you elaborate that? I thought it should never be null as long as the device can connect to firebase server.
U r right, there is not to be with permissions
@evollu it seems about half the time, the device token is missing. Both on initialize and refreshToken. Have you encountered this before?
if you are running with android emulator, can you check event log? There should be logs about firebase connection.
@evollu I have the same issue here and after some researches I think that Firebase just send the device token in this particular cases:
- First time that the app was open on device (just the first time);
- Security reasons that made Firebase change the token by it self;
- Manually Uninstall/Install app again on device;
But in my case for example, the token was generated on first time that the app was installed, after that, never more! I tried to uninstall/install the app and nothing happends! If anyone solve this problem, please, tell me, cause I have research everywhere and can't find anything.
I wonder if it is related to the device. Can you try the native sample project from firebase website and see if you still have the issue? If so, fire a bug to them
@evollu After try a lot of things to works on my device, I run in my emulator, and works. After that, I run in my device again and (I don't know why) works too and (I don't know why again) still working! ¬¬
I will try the native sample project anyway and I come back here to say what happends.
Tks a lot.
@woniesong92 is this solved?
I keep having a null registration id on application first boot. Is there any news about that?
can you try with Firebase native example? If you still see it, fire a bug to them
Are you guys sure that you have listened for the refreshToken event? I had the same issue especially when reinstalling the app on my phone because it took longer for getting the token.
So make sure you both of them:
Getting the Firebase token
🚨 Can be unavailable on first load
FCM.getFCMToken().then(token => {
console.log(token)
})
Listener for Firebase token
FCM.on('refreshToken', (token) => {
console.log(token)
})
This isn't solved. I haven't had the time to write up a reproduction steps but it seems to depend on the device version too. I made sure to listen to both the first load and the refreshToken.
I just figure out that in my case the problem is the company proxy server. The proxy was blocking the request to firebase and after I configure the proxy server properly to not block my device requests everything woks fine. I know this is a particular case but maybe can help someone.
I made THIS MODIFICATIONS on my forked version of this repo, this code force the refresh of token on firebase server. I really do not test yet, so if someone wants to implement this and do more tests, just feel free to do that.
firebase class file
final Intent intent = new Intent("tokenReceiver");
final LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(this);
intent.putExtra("token",refreshedToken);
broadcastManager.sendBroadcast(intent);
storeToken(refreshedToken);
//sendRegistrationToServer(refreshedToken);
MainActivity LocalBroadcastManager.getInstance(this).registerReceiver(tokenReceiver, new IntentFilter("tokenReceiver"));
BroadcastReceiver tokenReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { token = intent.getStringExtra("token"); if(token != null) { }
}
};
This code working fine
I have the same issue with some device the token is always be null
I can not get token in some devices first time but when I back to prevues page and come back to login I get the token but in some other devices like Samsung Galaxy G5 I'll never get the token and it's always be null
I solved this problem for my case. But I'm using Swift (iOS). After re-installing app and other actions my token was nil. I needed to wait didRefreshRegistrationToken function. So, I'm ignoring this nil with guard let token = Messaging.messaging().fcmToken else { return } and after this function func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) { is getting called. Hope it helps someone
Try to change the device language.It worked for me :)
I closed the emulator and started the app again from Android Studio. Then it invoked onTokenRefresh to get the new token.
This happens to me quite a lot I have to aggressively retry on both iOS and Android
This happens even now with MAUI Android. Im facing this null value issue recently on some android devices like vivo, samsung Fold & pixel kind of devices.
FYI, I'm generating the token via FirebaseMessagingService's OnNewToken override method.
Is there any workaround ?
This package is deprecated for a long time. You should use the react-native-firebase instead.
Im using mobile app MAUI. Any suggestions for it?
Do you mean .Net MAUI Framework?
Yes
And do you know what library, SDK, or plugin are you using to handle Firebase in the MAUI project?