Online or not

What would the proper way to know if a users device is connected to the internet or not?

Pings ?

That could be a way of doing it but somehow I assume that the iPhone it self would be aware if it is has internet or not so I think that a simple HasInternet() would be nice to have.

I also suspect that there is notifications that can inform my app that internet is available.

I wasn’t aware you were talking about iPhones.

This is the native way Apple presents as example in objective-C https://developer.apple.com/library/ios/samplecode/Reachability/Introduction/Intro.html

Maybe one must ask to implement such feature if it’s not present in any form.

Feedback request: <https://xojo.com/issue/37217>

Thanks for the assistance!

I’m must bumping this old thread in case anyone has worked out how to implement a call to Reachability in Xojo? I had a look at the docs and at Jason King’s Declare Maker but I’m afraid it is beyond me. I have an app that sometimes needs to synchronise large images with our web services. I want to give my users a way to tell the app to only do this sync when on wi-fi and so calling into Reachability to determine the connection type seems to be what I need to do.

This may be possible, but I’m not sure if we can declare into “ifaddrs”, “netdb” and some of the other libs included in that example. Unfortunately I don’t have the time to give it a test right now.

Thanks Jason. There’s certainly a lot of scope for Xojo to update iOS with new features and also for third party add-ons…

For my own app, I simply try to connect, and if there is no connectivity the HTTPSocket error signals there is no connectivity. I saw several methods around doing pretty much the same with the google site.

It is crude, but it works for me.

I don’t need to know whether I can get a connection, as my app has a local data cache so can operate without a connection if the services can’t be reached. I need to know what type of connection the user has as some of the data may be too large to post via a mobile data connection. Quite a few apps like mine allow the user to choose whether to submit data on Wi-Fi, Mobile or both types of connections. That’s what I’m wanting to offer.

Then you got to be patient, until that feature gets implemented…

Or you can ask your user to confirm he wants to proceed. Maybe after telling him to look at the icons in the status bar.

From what I see on my iPhone, when Wifi is not available but cell data is, it shows “4G” next to the operator name. Otherwise it shows the Wifi logo. Actually, while writing, I got this wild out of the box idea : since we can get a screen shot, it should be feasible to recognize the logo or the 4G in the picture…

I really enjoy some of your out-of-the-box suggestions Michel. :slight_smile:

My iPhone can display LTE, 4G, 3G, and Edge when it is not on wifi. There might be others as well for other carriers since thats just for AT&T. I like the idea, but I’m not sure about the feasibility of implementation :frowning:

It was just a wild idea… Maybe just detecting the WiFi logo would be enough. If it is not there but you have connectivity, you can safely assume it is some sort of cellular data connexion. Otherwise when the area is blank, there is no connectivity at all.

Ok I looked back through some of the documentation from Apple, and it is actually much easier that the project linked to above. Try this:
https://www.dropbox.com/s/uysk3px4jjbcm6t/reachability.xojo_binary_project?dl=0

To use, create a new Reachability object, then check the boolean properties to determine how the device is connected (Wifi, Cellular, not at all). That’s it. Enjoy!

Nailed it. Thanks Jason! :slight_smile:

You’re welcome

Great! Nearly there… Copied the Reachability declare and now what?

Your example from the open event is how to create it?

dim r as new Reachability
Break

if Reachability.isReachable = True then

Tells me “This item does not exist”

What do I have to do? Please go easy and slow… Thanks Jason :slight_smile:

Here you go:

dim r as new Reachability if r.isReachable then // Do something else // Do something else end

Thanks!!! If it’s that simple, why can’t I see it? Learning curve high… Thanks! :slight_smile: