Firebas and ionic issues

FIREBASE AND IONIC are great combination for mobile Apps, But there is an issue with both combination, i have created an App with both and noticed that at times the App just wont connect to Firebase to fetch data and some times is just so fast this loading and hanging factor is not good…

This hanging or loading forever problem is a big issue because it can cause a lot of App uninstall from users, i have read through similar topics e.g

http://forum.ionicframework.com/t/ionic-firebase-stuck-loading-forever/31146/1453

BUT None Of these Solves my problem, i think this issue should be taking more seriously by ionic because Firebase and Ionic is a very Good combination.

THERE IS ALSO SOMETHING THAT I NOTICED IN ONE OF THE POST ABOUT “firebase:previous_websocket_failure” AND THAT WHEN THE VALUE IS SET TO TRUE THATS WHAT BRINGS ABOUT THE APP NOT BEEN ABLE TO CONNECT UNLESS YOU RESTART THE APP

SO DOES ANYBODY HAVE A SAMPLE CODE OF ALWAYS SETTING THIS VALUE TO FALSE WHEN ITS SET TO TRUE IN FIREBASE.

ANY HELP ON THIS FIREBASE LOADING AND HANGING ISSUE WILL BE APPRECIATED

I agree that Firebase has its flaws.

This one has bothered me the longest time.

However, I had a chat with one of the firebase developers, who ended up suggesting to handle the Firebase connections myself.

Meaning, I chose when to Firebase.goOnline() and Firebase.goOffline()

In my case, I am doing Firebase.goOffline() as soon as the app is paused (put in background), and Firebase.goOnline() as soon as it resumes.

And something that simple, seems to be working so far. Give it a try.

Thanks Pierro for the suggestions i will give it a try, But i doubt if the issue is going online or about going offline, Since most times the Firebase request just get Stock forever,

One thing i want to ask you Pierro is that Does handling your connections on firebase prevents it from the Loading stall that sometime occurs when fetching data? Or calling the firebase Go online does it help to Clear the “firebase:previous_websocket_failure” i talked about?

can you please give me and insight on the kind of problem you had with firebase before you handled the connections your self.

And finally can you give me and Example code and where to initiate the goOnline and Offline ? is it on the controller or App.js

Anyway i will appreciate your response

Thanks

Very simply, this is what I do (in the app.js, within ionicplatform.ready) :

document.addEventListener("resume", function () {
    Firebase.goOnline();
},false);  
		
document.addEventListener("pause", function () {
    Firebase.goOffline();
},false); 

To make things clear, launching Firebase.goOnline() by itself won’t work to reconnect the dead socket.
It will only work if Firebase.goOffline() was launched before.

But since this dead socket only happens when the app is in background, this piece of code does its job pretty well.

Pierro Thanks Once again, for the code snippet, But the Dead Socket does not just happen when the app is in Background. It happens When the App is open and you are trying to Pull a data from the the Firebase server it just keep loading forever or just give a blank page and just stay there until the app is relaunched,

What i am looking at is also how to also grammatically set the firebase:previous_websocket_failure
to false so it can re attempt to open a new connection.
I will also implement the goOnline() and goOffline() and see if it helps
All the same Thanks for your Input

I know what you mean, when you say the pulling data gets stuck forever.

However that socket died when you first put the app in background at least once for a time long enough to timeout. (that timeout is random though…)

What I’m trying to say is, for a socket to die, it had to be put in background at least once.
I have never encountered a problem where, I launch the app (a real launch, not from a pause state but also with the splashscreen etc), I stay on it without pausing, and suddenly my socket dies. There always had to be some background time for the socket to die…

I don’t know if it’s clear. But anyway, let me know how this snippet goes for you.

Thanks Pierro I also Noticed that the failures are due to bad internet connections at times and when the connection stabilize its still stuck
Thanks Piero

Oh… bad internet connection is the worst. :frowning:

I’m using $cordovaNetwork plugin to take care of that.
It bothered me too long, now when I get shitty network or no network at all, I just launch a popup that won’t leave until the connection is back :slight_smile: Better blocking the app than let the user believe it’s working when it’s not… (one of the cons of firebase in some cases, to update the view as if the database was updated, even when it’s not)

$rootScope.$on('$cordovaNetwork:offline', function() {
    $ionicLoading.hide();
    $rootScope.offlineMod.show();
});

It’s true that these are all workarounds though… I still believe there are issues with firebase that need to be taken care of with ionic.

Hello Pierro i am still implementing your solutions you gave but please i need to ask you a question IS IT POSSIBLE TO WRITE FIREBASE RULES WITHOUT USING THEIR AUTH E.G USE IONIC AUTH THEN FIREBASE AS BACK END . HOW WOULD ONE SECURE FIREBASE?

It is very much possible indeed, however regarding the security rules without firebase auth I am very skeptical…

Most - if not all - of my security rules uses auth != null or $userid == auth.id, without auth I’m not so sure how you can secure your app.
I guess it depends on what you are trying to do…

Then What that means is that When you use IONIC for YOUR Authentication and Firebase Fore your Back end You cant Secure Your FireBase.

So must must use Firebase Authentication in order to secure your App.

Do you have any App in the app Store i can see?

I am no expert, but as far as i know YES, you cant really secure your firebase without firebase auth.

I released an app for couples on the Apple store, called “Bloom - game for couples”, i am using firebase login (+ Facebook ) and lots of firebase sécurity rules to make the whole thing private for couples.

1 Like

cher pierro
je veux faire ca en ionic 2 pleaze

Malheureusement Tarik je ne maitrise pas du tout Ionic 2 pour le moment…

Mais je suis en cours de développement d’une application sur Ionic 2, et puisque je vais très prochainement faire face à ce même problème à nouveau, je te répondrai à ce moment là. :wink:

cher pierro
merci pour la réponse et j’espère savoir le mot clé de ce problème pour rechercher dans autres sites car j’ai cherche beaucoup et j’ai pas trouvé .