@andrecaribe, the easiest way to check if you are connected is to try to access google.com or a website that is available via an internet connection using sockets or UrlLoader.
@andecaribe, to answer the second part of your question, determining the connection type, it can be done only on the iOS platform (for the moment) as Apple have a reachability API only for the iOS, so you cannot use that on other platforms. In case you were still looking for an answer to that question.
@phongtt could you give a sample code of how you check it the internet connection is active please? While offline, I have tried using :
local loader = UrlLoader.new("www.google.com")print(loader)
I was expecting loader to be nil to check if it's available or not but it seems not to be the case. How do you deal with that? Or maybe @OZApps I know that you always come up with great suggestions.
The httpStatusCode will be a 503 ("Service unavailable") after a LOOONG timeout for UrlLoader if there is no connection. Personally, I try to load a known URL (using HTTP GET) and set a timer for it. If there's no response within my personal timeout limit, then I put up an alert to the user saying there's no internet connection.
@OZApps is right for iOS - if you are trying to determine the "type" of connection you have, "Reachability" is the way. See modern variants such as:
I was wondering what the purpose of "Application:canOpenUrl" was, though. It does seem to return "true" even if the connection is not available. @ar2rsawseen is canOpenUrl checking if the url is well formed only?
I assumed it was checking both (well formed url + available connection), wouldn't it actually make things easier if that was the case? Or maybe I am missing the other part of the iceberg
I think you're misunderstanding what a URL is. It has nothing to do with whether you're connected online and is actually designed to be a way to reach a resource - hence it's name: "Uniform Resource Locator" (see http://en.wikipedia.org/wiki/Uniform_resource_locator for a pretty good laymen's explanation compared to the RFCs.)
On iOS, there are a few standard URL schemes (or protocols) that don't assume a connection. Consider: mailto:foo@bar.com - even if the device isn't online, Mail.app still opens with a blank mail populated with the address foo@bar.com in the To: field. Similarly, http or https opens Safari, tel: opens the Phone app, etc.
There are literally thousands of custom URL schemes (the first bit of the URL) that allow interconnectivity between apps. Here's a database that people have volunteered information for (for iOS only): http://handleopenurl.com
So for example, if you register a custom URL scheme on iOS with your app, and someone receives an email with a link inside the email like:
theWindApp://abc/?a=1&b=2
If they click on the link in the email AND your app is installed on their iOS device, it would launch and open to the appropriate resource (eg. a specific page in an ebook app that triggers a specific animation, or a bonus reward sent from one user to another etc.)
@ianchia Thanks a lot, great answer. I have been using launch center pro + drafts + editorial for months, but didn't make the connection with it used in Gideros.
I love this community @phongtt thanks for searching! @ianchia I am planning to do some dev this night after work, your code will help me save a lot of time, thanks again.
Comments
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
could you give a sample code of how you check it the internet connection is active please?
While offline, I have tried using :
How do you deal with that? Or maybe @OZApps I know that you always come up with great suggestions.
Edit :
Also tried this : UrlLoaderEvent.ERROR :
@OZApps is right for iOS - if you are trying to determine the "type" of connection you have, "Reachability" is the way. See modern variants such as:
https://github.com/kstenerud/KSReachability
https://github.com/tonymillion/Reachability
Hope this helps,
- Ian
Best,
- Ian.
Likes: Mells
thanks a lot.
I was wondering what the purpose of "Application:canOpenUrl" was, though.
It does seem to return "true" even if the connection is not available.
@ar2rsawseen is canOpenUrl checking if the url is well formed only?
I assumed it was checking both (well formed url + available connection), wouldn't it actually make things easier if that was the case? Or maybe I am missing the other part of the iceberg
Likes: Mells
I think you're misunderstanding what a URL is. It has nothing to do with whether you're connected online and is actually designed to be a way to reach a resource - hence it's name: "Uniform Resource Locator" (see http://en.wikipedia.org/wiki/Uniform_resource_locator for a pretty good laymen's explanation compared to the RFCs.)
On iOS, there are a few standard URL schemes (or protocols) that don't assume a connection. Consider: mailto:foo@bar.com - even if the device isn't online, Mail.app still opens with a blank mail populated with the address foo@bar.com in the To: field. Similarly, http or https opens Safari, tel: opens the Phone app, etc.
There are literally thousands of custom URL schemes (the first bit of the URL) that allow interconnectivity between apps. Here's a database that people have volunteered information for (for iOS only): http://handleopenurl.com
Apple's iOS docs on openURL:
https://developer.apple.com/library/ios/documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:openURL:sourceApplication:annotation:
Intro to iOS URL scheme:
https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007899
So for example, if you register a custom URL scheme on iOS with your app, and someone receives an email with a link inside the email like:
theWindApp://abc/?a=1&b=2
If they click on the link in the email AND your app is installed on their iOS device, it would launch and open to the appropriate resource (eg. a specific page in an ebook app that triggers a specific animation, or a bonus reward sent from one user to another etc.)
Does that make more sense about opening URLs now?
- Ian
Likes: hgvyas123, Mells
Thanks a lot, great answer.
I have been using launch center pro + drafts + editorial for months, but didn't make the connection with it used in Gideros.
Anyway, @ianchia has a great answer
@phongtt thanks for searching!
@ianchia I am planning to do some dev this night after work, your code will help me save a lot of time, thanks again.