Network upload and applicationSuspend

background: I’m working on an app that saves a photo with additional information about it.  The data needs to be pushed up to the cloud.  I also need offline support, so I have a local sqlite database to hold the info.

My workflow is:

  1.  Save all data locally.

  2.  Check for internet.  If internet proceed to step 3, otherwise resume other tasks

  3.  Check if local record has referenceId from sever.  If not proceed to step 4, otherwise resume other tasks

  4.  Upload data to server (create a db record)

  5.  Upload photo (file)

  6.  Link photo to data

  7.  Save reference to local sqlite.

  8.  On applicationResume or applicationOpen events, I jump to step 2.

My problem happens with network access drops or an application suspend (http://docs.coronalabs.com/api/event/system/type.html).  The gotchas for all the network request and upload (http://docs.coronalabs.com/api/library/network/request.html#gotchas) indicate no callbacks are sent.

The majority of my issues occur during photo upload.  If uploading the photo takes a long time, odds are a suspend event will occur and either stop the upload/request or block the callback.  I try to upload the file again during applicationResume/applicationOpen event resulting in multiple uploads.  

Usually, inactivity is the reason why the upload fails.   Does anyone know how to prevent this?  Is there a way to reset the inactivity timer?

I really want to avoid a message on the screen saying “please tap so the device does not go to sleep and cancel your upload”

Look at system.setIdleTimer API. http://docs.coronalabs.com/api/library/system/setIdleTimer.html

You can use it to disable the systems ability to go to sleep. Make sure to reset it back once your upload is done though. Hope this helps.

Wow… I can’t believe I didn’t notice this function before. 

Thanks a TON!

You are most welcome. Sounds like you have an interesting project. Look forward to hearing more about it once you release it. Best of luck!

Look at system.setIdleTimer API. http://docs.coronalabs.com/api/library/system/setIdleTimer.html

You can use it to disable the systems ability to go to sleep. Make sure to reset it back once your upload is done though. Hope this helps.

Wow… I can’t believe I didn’t notice this function before. 

Thanks a TON!

You are most welcome. Sounds like you have an interesting project. Look forward to hearing more about it once you release it. Best of luck!