Check for network connectivity...While statement

You must Login before you can answer or comment on any questions.

Hey, Guys

I'm having some problems to do a While statement to block my app. In my case, in the begin of the code, I check if the internet is active and if not I do a While to block 'while' the internet not return:

I tried this two ways:

while (Titanium.Network.networkType == Titanium.Network.NETWORK_NONE){ }

and

if(!Titanium.Network.online){}

Is there something missing from my code? Thanks.

— asked 7 months ago by Rafael Coelho
1 Comment
  • Well, Titanium.Network.online works for me on iOS, so you will have to give us more information to work with … What kind of problem are you getting ?

    — commented 7 months ago by Thierry Godfroid

1 Answer

Using a while statement like this assumes that you will be looping over something until a certain criteria is met, at which point you will execute some other code, but the while loop in this case is only checked on the first run.

If you have no network, and you want to execute some function or code when you get the network back, you should listen for the network change event. When the change event is fired, check to see if the network matches your criteria, then execute the necessary code.

Your Answer

Think you can help? Login to answer this question!