-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't use initFirebase() on 1.1.3 [Firebase isn't initialised] [Solutions proposed] #822
Comments
Ok when i downgrade to 1.0.5 it seems to work well, but as soon as i get to latest versions it doesn't work. Firebase JS needs to be compatible with plugin version. How can this be properly solved ? |
Same issue here. Using:
Thanks |
initFirebase problem should be fixed declaring just below import section: |
@DomCostantino Doesn't work for me : |
I had this same issue. Got rid of the 'Firebase isn't initialised' error by downgrading to 1.0.5:
|
Same problem. I created a stackoverflow question with a 50 reputation bounty https://stackoverflow.com/questions/52140850/firebase-isnt-initialised-on-ios-ionic/52186436 |
@SimonKomlos this might be because iOS is still on firebase SDK 4.13.0 (see #796). I believe android is on the latest firebase version. |
@soumak77 i don't think so, i have the same problem on Android with latest updates. as i told Firebase JS needs to be compatible with plugin version. |
@BrainOverflown I was specifically talking about the stackoverflow question @SimonKomlos posted. Though if v1.0.5 works, then I'm wrong since it's also on v4.13.0 for iOS. |
@soumak77 got it ! Solution to this problem will make a lot of happy people. People should try downgrading to 0.1.18 as advised on the Stackoverflow thread :
|
@BrainOverflown did downgrading fix the problem for you? |
@SimonKomlos Yes, but people should be very careful because when you install by editing your config.xml, it will automatically be renammed from "1.0.5" to "^1.0.5" (this caracter is making cordova build the platform with latest version and not 1.0.5). |
@BrainOverflown Okay, thanks. Did you do |
Downgrading to 1.0.5 worked for me! |
@SimonKomlos I tried 1.0.5 and it does work. But for some configurations going down to 0.1.18 may be useful so people reading this better try both if 1.0.5 doesn't work i guess.. |
while downgrading to 1.0.5, firebase getToken function throws an error like class not found please suggest me in which down version getToken will work? |
@ajaykumar2897 Test this different steps :
If it's not ok give encountered problems here so we can help troubleshoot. Good luck |
Was able to use the |
Based on @BrainOverflown, I managed to make it working (the 1.1.3 version) by calling these methods in my app.components.ts, just after the device is ready
You also need to declare Firebase Plugin to use it
Best |
@tgensol Thanks, i updated my previous post with the same variable declaration as yours for consistency. |
It appears the root cause of this issue as determined by @briantq was that the Crashlytics PR (#784) removed the auto-init functionality. Would any be able to help investigate and figure out what code needs to be added back to fix this? I would love to accept a PR and push out a new patch release so that those adopting v1.1.x don't have to change their code to get the plugin to work as it used to work (i.e. no breaking changes). |
For anyone having this issue, could you please try testing with a branch for a proposed Pull Request PR#830. Run If you could confirm whether or not this resolves the issue, that would be helpful. I want to make sure people don't work around this issue instead of just solving it. We are going to be removing the initFirebase() method ASAP so if you do modify your code to work around it, you will have to undo the modification in the coming days. |
@briantq, working here. $ ng info
$ ionic info
package.json
|
Guys, confirmed. You just need to add the FirebasePlugin.initFirebase method before using Firebase. And then in it's success callback get your token: IE: //Inits Firebase
FirebasePlugin.initFirebase(
function(){
//Subscribes for token refresh event
window.FirebasePlugin.onTokenRefresh(
function(token) {
console.log("Device token refresh: " + token);
//Your token handling functions
},
function(error) {
console.error("Firebase error: " + error);
}
);
},
function(error) {
console.error("Firebase error: " + error);
}
); |
For all those running into this issue, it was caused by a PR which removed auto-init functionality. This is being put back in place via #830, which will remove the unnecessary |
I have verified the pull request removes the need to call |
@qswinson I was just thinking about the same thing, especially since there are two bugs that were opened in the past couple days about analytics not working. I feel like maybe we should enable those by default but allow some parameter that you can use to turn them off. I would expect many people would expect the APIs to just work which could cause confusion, even if we document that the feature is disabled by default. @soumak77 do you have an opinion on on/off be default? |
It seems like the plugin would be easier to adopt if everything just worked right away. For advanced users, they can choose which features should be turned off based on their app's requirements. With that said, we should add some cordova configuration variables which allows disabling certain features. |
This should be fix via |
I just updated cordova-plugin-firebase to 1.1.3 and tried to use the
initFirebase()
method to get rid of the 'Firebase isn't initialised' error (note that the error got a typo in console log).I'm getting the following error :
Uncaught (in promise): TypeError: _this.firebase.initFirebase is not a function TypeError: _this.firebase.initFirebase is not a function
my code : (note that this code [without initFirebase()] is totally working on another computer.
import {Firebase} from "@ionic-native/firebase"; public start() { return this.platform.ready().then(() => { this.firebase.initFirebase(); this.firebase.getToken().then(token => { console.log(token) this.api.post('tg.php', {token}).subscribe(() => { }); } ).catch(err => console.log(err)); }); }
***** EDIT ***** :
For those encountering the same problem, here is a walkthrough which seems to help most people :
cordova plugin rm cordova-plugin-firebase
cordova plugin add [email protected]
npm install --save @ionic-native/firebase
if it doesn't work
cordova plugin add [email protected]
thennpm install @ionic-native/firebase --save
if it doesn't work
declare var FirebasePlugin : any;
<script type="text/javascript" src="cordova.js"></script>
FirebasePlugin.initFirebase();
For those needing a practical example of how to insert it in your own code, here is a snippet courtesy of @tgensol :
observableFromEvent(document, 'deviceready').pipe(first()).subscribe(() => {
FirebasePlugin.initFirebase();
FirebasePlugin.initAnalytics();
})
Depending on how you coded your application, this may have to go in your home.ts /or/ typescript associated with the page calling it /or/ in the provider calling for the getToken() functio.
If the problem isn't solved with this step by step, write down the encountered problems here so we can help troubleshoot for you and others.
[important note : for people having a hard time downgrading, try deleting manually plugins and platforms folders (after backuping them/!), then after plugin installation go for a :
cordova platform add android
]Good luck
(follow the thread for credits of contributors)
The text was updated successfully, but these errors were encountered: