Best Practices: Internet Dependent Apps when used Offline

I’ve been a Corona user for 18 months now, and I’m nearly ready to submit my first business app to the store. Woohoo!  The app has a few simple features, the main one being tableView list of products (with images) that relies on internet access to download new product content.

If the device loses connectivity, or is loaded in airplane mode, the app runs into problems.  I am wondering what is the best approach to this problem.

Should I check for internet connectivity on boot and restrict features when offline?  (What if they loose connectivity half-way thru using the app)

Should I pop up a native.alert that forces the user to close the app entirely?   (Is that even an option since os.exit is forbidden?)  

What is the most professional approach to handling an application losing network access? 

At this point my biggest concern is to submit a finished product with the least risk of crashing.  =]

Any and all advice is welcome. I hope the above questions and scenario are clear. thanks in advance.

-Simon

I would suggest that the most sound practice would be to check for network connectivity right before you actually need to make a network call.  If it has to have connectivity, popup a native alert saying you need network connectivity, but if possible, silently fail and only show them the current information you have.

Rob

Ideally, you will have store some of the data locally, and delete it/refresh it when new data is retrieved.  Kind of hard to say depending on what the app really does and if that even makes sense to do. 

But in my app, for all of my online functions, I do a quick connection test, and if it fails, I do a native alert telling the user that Internet connectivity is required for that.

Someone posted this code a while back, and is definitely worth using.

In your main.lua, add:

local connection = require( "connection" )

Then create a separate connection.lua file with this:

module(..., package.seeall) local socket = require("socket") function test() local connection = socket.tcp() connection:settimeout(1000) local result = connection:connect("www.google.com", 80) connection:close() if (result) then return true end return false end

Then to test if there is a connection, do:

if ( connection.test() ) then -- do Internet stuff else -- display messaging or offline mode stuff end

Hey Rob Miracle and theGdog, thanks for the replies–this advice was exactly what I was looking for. 

I’ve now made offline copies of default images to use when the network request fails, and it seems like i’ve patched up most of the potential problem areas. 

I’m looking forward to sharing my app once it’s live =]

I would suggest that the most sound practice would be to check for network connectivity right before you actually need to make a network call.  If it has to have connectivity, popup a native alert saying you need network connectivity, but if possible, silently fail and only show them the current information you have.

Rob

Ideally, you will have store some of the data locally, and delete it/refresh it when new data is retrieved.  Kind of hard to say depending on what the app really does and if that even makes sense to do. 

But in my app, for all of my online functions, I do a quick connection test, and if it fails, I do a native alert telling the user that Internet connectivity is required for that.

Someone posted this code a while back, and is definitely worth using.

In your main.lua, add:

local connection = require( "connection" )

Then create a separate connection.lua file with this:

module(..., package.seeall) local socket = require("socket") function test() local connection = socket.tcp() connection:settimeout(1000) local result = connection:connect("www.google.com", 80) connection:close() if (result) then return true end return false end

Then to test if there is a connection, do:

if ( connection.test() ) then -- do Internet stuff else -- display messaging or offline mode stuff end

Hey Rob Miracle and theGdog, thanks for the replies–this advice was exactly what I was looking for. 

I’ve now made offline copies of default images to use when the network request fails, and it seems like i’ve patched up most of the potential problem areas. 

I’m looking forward to sharing my app once it’s live =]