:fire: I recently migrated my app from a firebase project to another. I set up everything to point to the new project while keeping my pods and libraries. What's happening is that I do not receive a push notification through Cloud Messaging
until I uninstall and re-install the app. I am retrieving tokens through firebase.messaging().getToken()
.
firebase.messaging().onTokenRefresh()
is NEVER retrieving tokens, even after uninstall and re-install. That's why I am using getToken()
.deleteToken()
then getToken()
and no result.Could the token retrieved (without uninstalling the app) be somehow related to the old project, not the old one?
My question is, can I get the token to work without uninstalling because I already have a set of users using the old version and when they update to the new one they're not gonna receive push notifications anymore :/ :fire:
ios/Podfile
:pod 'Firebase/Core'
pod 'GoogleIDFASupport'
pod 'Firebase/AdMob'
pod 'Firebase/Messaging'
pod 'Firebase/Auth'
pod 'Crashlytics'
AppDelegate.m
:#import <Firebase.h>
#import "RNFirebaseMessaging.h"
#import "RNFirebaseNotifications.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
[FIRApp configure];
[RNFirebaseNotifications configure];
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
[FIRMessaging messaging].delegate = self;
//other code here...
return YES;
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[[RNFirebaseNotifications instance] didReceiveLocalNotification:notification];
}
@end
Not developing Android at the moment.
iOS 11+
10.13.6
N/A
N/A
XCode 10.1
React Native
version:0.57.8
React Native Firebase
library version:5.2.3
Firebase
module(s) you're using that has the issue:TypeScript
?N/A
ExpoKit
?ExpoKit
N/A
Me too.
iOS is strange.
Android is not problem, it is still getting notifications usually.
Anyway, I'm asking this problem on apple developer forum
https://forums.developer.apple.com/thread/114436
Cool, please let me know if you manage to find a solution!
@BaderSerhan I wrote this code.
import Firebase from 'react-native-firebase';
import { AsyncStorage, Platform } from 'react-native';
if (Platform.OS === 'ios') {
Promise.resolve().then(() => {
return new Promise((resolve, reject) => {
AsyncStorage.getItem('isRefreshedFirebase').then(_value => {
if (_value !== 'refreshed') {
Firebase.iid()
.delete()
.then(_result => {
AsyncStorage.setItem('isRefreshedFirebase', 'refreshed').then(
_result => {
resolve();
}
);
})
.catch(_err => {
reject();
});
}
});
});
});
}
Above might solve the issue.
(Sorry, I don't have a test device anymore. I have reinstalled the app...)
Firebase.iid().delete()
seems to be important.
This function seems to delete all past token information which might corrupt newer one completely.
ref. https://github.com/firebase/firebase-ios-sdk/issues/2499#issuecomment-472654007
I also am having this problem with my iOS app.
After fresh install, notifications work great, I log in and out of my app with different users and push messages work great.
Once the app is closed, and reopened, they no longer work
As @keech suggested, I am calling Firebase.iid().delete()
in the componentDidMount
method of my App.js, but that does not resolve the issue.
using same react-native-firebase version as @BaderSerhan
Everything works 100% in Android.
Having the exact same issue - works fine if app is reinstalled, but not if updated. I've tried calling Firebase.iid().delete() as well and am able to test since the updated app is in TestFlight and the previous one is still in the app store. Have deleted the app, installed app store version, updated to TestFlight version, doesn't work. Uninstalling, then clean installing TestFlight version works fine.
Has anyone had any success solving this?
Any updates?
Same here
Same for me. it's working well for android but ios don't have anymore push notification.
Did anyone try the code from @keech ?
@mikehardy yes, that and everything else similar that I could think of. Only a full uninstall and reinstall of the iOS app works
Come on. This issue exists for 1.5 years with this library! My users are struggling all the time with it. It's really painful for success of the app.
I've started looking for a workaround.
@andrewkslv https://github.com/invertase/react-native-firebase/graphs/contributors :thinking: always room for another contributor right?
@mikehardy absolutely!
@andrewkslv https://github.com/invertase/react-native-firebase/graphs/contributors 馃 always room for another contributor right?
The reality of contributors is more like this: https://github.com/invertase/react-native-firebase/graphs/contributors?from=2019-01-01&to=2019-05-24&type=c
9 times out of 10 with issues on GitHub relating to notifications is it's either a duplicate issue or an incorrect setup; which makes it really hard to find genuine bug related issues, even the incorrect setup issues can take hours to triage each (I've even screen shared with quite a few people to do just that) - but given the limited contributors right now we have to balance between triaging issues and keeping the library up to date with React Native & the Firebase SDKs.
I'd love to help out everyone and I feel like I'm letting people down if I don't but right now until v6 is out (fixes so many issues and also moves many setup steps internally (so incorrect setups is less likely)) my time is limited.
If we can help more people contribute that'd be great and we're looking at ways we can incentivise this from v6 onwards including mentorship and also allowing maintainers to invoice for time spent via our open collective.
Without @mikehardy helping out triaging issues I'd have probably gone insane by now 馃檭 - so thanks, Mike. True MVP.
After so long having headache because of this problem, I think I finally found the solution.
There's a very important method not mentioned in the documentation:
firebase.messaging().ios.registerForRemoteNotifications();
I hope it helps someone else!
@Salakar that last comment might be interesting as I go to do a demonstration - I double-checked the docs and the API and it is true that this IOS-specific API is not mentioned in the general documentation as being necessary, but in my app I have received push notifications (I think?) on iOS without calling it. I'm using firebase to send the messages though, perhaps it handles it correctly? Or maybe I'm imagining things and this is actually vital to receive any sort of remote messages on iOS? If it is, it might be worth connecting the iOS messaging install doc to that API link with a mention it is important
@arojunior I just examined this with @Salakar - the docs consistently mention you need to call requestPermission(), and that method calls registerForRemoteNotifications internally.
So if you are following the docs and calling requestPermission the registerForRemoteNotifications call should not be needed
This may be the case for @BaderSerhan - not getting notification permission - as well but that is unknown.
@mikehardy Ok, but in iOS environment you are not allowed to call the requestPermission() twice. So if the user deny the request in the very first time and then allow from the device settings (the only way to do it after deny), so it won't be called.
Another point: We are talking about an App that already has permission, because it was already installed (just not using firebase yet), so the firebase.messaging().ios.registerForRemoteNotifications();
method won't be called as well.
That's why it works when you uninstall and make a new fresh installation, because in that scenario you call requestPermission() method.
@arojunior it was my understanding you could call it as much as you wanted, but the user would only see the dialog once? Which means if it is vital to do notifications you have to do a checkPermission first and handle the tri-state well (undetermined, granted, denied) by sending denied people to the system settings yes
But as far as I know it's never wrong to call requestPermissions - thus you'd get the register API call.
Having the two items (registering for remote notifications + asking for permission on local) isn't great and I believe @Salakar put that on the v6 list in response to the investigation today, but it is a pattern that should work for most (maybe all)
If you want to make a docs PR right around the documentation for "requestPermission" mentioning that if you don't use this but still want remote messaging on iOS you need to use (then include a link to the registerForRemoteNotifications API), that might help people. PRs for docs can be made by hitting the edit button on each doc page and then right in the GitHub UI you can edit it and post the PR
I have met same problem, and A few survey on native code. I found my problem that js Initialized method at native code is clalled earlier than onTokenRefresh because the definition is not located in root component lifecycle. This causes event emit onTokenRefresh though the callback is not ready. I moved onTokenRefresh to didmount event in first rendered component, then it is solved. Try it if you find onTokenRefresh are called after jsInitialized event.
Hello 馃憢, to help manage issues we automatically close stale issues.
This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?
This issue will be closed in 15 days if no further activity occurs.
Thank you for your contributions.
Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.
Thank you, everyone, for your valuable input to this issue. Unfortunately, I have been put to work on a different feature so I was not able to put time on this issue. As soon as I get time to recheck this issue and find a fix, I'll submit feedback and even collaborate suggesting a fix or updating the docs.
As for this:
This may be the case for @BaderSerhan - not getting notification permission - as well but that is unknown.
I am actually only checking if my user object is not saved in AsyncStorage, i.e. first install or re-install.
firebase.messaging().hasPermission()
.then(enabled => {
if (enabled) {
this.getDeviceToken()
} else {
firebase.messaging().requestPermission()
.then(() => {
this.getDeviceToken()
})
}
})
So, maybe I should call this function on every open of the app (at least temporarily until all users have migrated to the new version). I'll confirm when I try it out.
Hi @BaderSerhan, Any update related to this issue? We released three days ago and we had the same problem. Users having iOS don't know that they have to re-install the app and of course the don't receive notifications.
Hey @fgagneten. Did you try what I said? I've solved my problem with that.
@arojunior solved it for me! Thanks!
@arojunior mmm, how does it behave for users which did not give permissions, I assume it will be requesting them permissions again and again everytime they open the app, am I right?
Hi @elribonazo ! As I mentioned here, calling that method will just work if your app already has permissions. In case the app got no permissions, it will do nothing.
If you want to request permissions, you need to use another method.
Please, read the whole thread to understand the scenario.
Tell me if I help you in anything else.
I dropped from this solution, which i read in another thread because calling this .ios method throws an exception.
What i've done finally is what is mostly recommended everywhere. To remove the tokens from our database on logout and even if the device push token is the same, the user won't have it active on their account, removing the need of removing the token.
thanks a lot for help anyway
@arojunior solved it for me! Thanks!
solved it for me too.
Most helpful comment
@mikehardy Ok, but in iOS environment you are not allowed to call the requestPermission() twice. So if the user deny the request in the very first time and then allow from the device settings (the only way to do it after deny), so it won't be called.
Another point: We are talking about an App that already has permission, because it was already installed (just not using firebase yet), so the
firebase.messaging().ios.registerForRemoteNotifications();
method won't be called as well.That's why it works when you uninstall and make a new fresh installation, because in that scenario you call requestPermission() method.