Check For Internet Connection

Hi Andrew

Thanks for your answer

Sorry I didn’t explain well.

I didn’t put this code within a loop.

Like you say I simply wrap it in a function and call it to test network availability before critical user actions.

But I noticed that with this call, Xcode console shows this message each second :

 

WiFi:[419334385.238658]: 

Too frequent(3.034801 secs) rssi event from driver

 

Do you have this message too in your Xcode Organizer Console?

Thanks

 

Olivier

Nope, I don’t see that message in my Console log.

  • Andrew

fwiw, hth: network.getConnectionStatus() can be used as a first-pass fail-fast test
it’s undocumented, but you probably have it, try: print(type(network.getConnectionStatus))

given that network.setStatusListener() doesn’t seem to work on Android, and is flaky on iOS, you can use getConnectionStatus() to “decide” if it’s even worth doing a more exhaustive (and potentially blocking) network request (via network api or socket lib or etc).

if the returnvalue.isConnected == false, then no point continuing. if true, you still need a more exhaustive second pass (cuz “is connected” does NOT mean “have useful internet”) but second pass will now be less likely to block

BUT, as it’s undocumented, if you choose to use it, I guess you’d have to test it with each release, as I suppose there’s no guarantee it wouldn’t just vanish some day

Hi Guys,

Did you find a solution to avoid freezing app?

I noticed that with the code above, Xcode console shows this message each second :

WiFi:[419334385.238658]: 

Too frequent(3.034801 secs) rssi event from driver

As if checking for internet connexion periodically

Can’t we check only one time and then stop the loop?

Thanks for your help

Best,

Olivier

Hi Guys,

Did you find a solution to avoid freezing app?

I noticed that with the code above, Xcode console shows this message each second :

 

WiFi:[419334385.238658]: 

Too frequent(3.034801 secs) rssi event from driver

 

As if checking for internet connexion periodically

Can’t we check only  one time  and then stop the loop?

 

Thanks for your help

Best,

 

Olivier

Hi there,

I don’t think you should place this code within a loop (such as a repeating timer.performWithDelay), especially at a frequency of one second.  If the socket takes more than one second to open and close, you’ll be opening more and more sockets to the same host, which is bad.

Instead, in my experience it’s worked well simply to wrap it in a function and call it to test network availability before critical user actions (such as attempting an IAP, attempting to share on social media, etc.), and alerting them if they don’t have a network connection.

  • Andrew

Hi Andrew

Thanks for your answer

Sorry I didn’t explain well.

I didn’t put this code within a loop.

Like you say I simply wrap it in a function and call it to test network availability before critical user actions.

But I noticed that with this call, Xcode console shows this message each second :

 

WiFi:[419334385.238658]: 

Too frequent(3.034801 secs) rssi event from driver

 

Do you have this message too in your Xcode Organizer Console?

Thanks

 

Olivier

Nope, I don’t see that message in my Console log.

  • Andrew

fwiw, hth: network.getConnectionStatus() can be used as a first-pass fail-fast test
it’s undocumented, but you probably have it, try: print(type(network.getConnectionStatus))

given that network.setStatusListener() doesn’t seem to work on Android, and is flaky on iOS, you can use getConnectionStatus() to “decide” if it’s even worth doing a more exhaustive (and potentially blocking) network request (via network api or socket lib or etc).

if the returnvalue.isConnected == false, then no point continuing. if true, you still need a more exhaustive second pass (cuz “is connected” does NOT mean “have useful internet”) but second pass will now be less likely to block

BUT, as it’s undocumented, if you choose to use it, I guess you’d have to test it with each release, as I suppose there’s no guarantee it wouldn’t just vanish some day