3

I have a hybrid-remote app that's using javascript remoting and offline storage using SmartStore. I had considered using SmartSync or StoreCache to make my life easier but its my understanding they use the forceTK library and the API. In my case I really don't need that since I'm using javascript remoting. Is that understanding correct?

What I would like to do however is know when the connection is restored so I can call my @remoteAction method to sync/save the updates. Is there a way to register a callback or setup a listener to know when the internet connection is restored?

Thanks!

4

There's actually no need to detect a HTML5 event by yourself. If you are building a hybrid app (as you mentioned) using the Force.com Mobile SDK, you can directly use the Cordova offline and online listeners. The Mobile SDK uses Cordova internally so all methods are available.

Detailed info is available here

Relevant code/events

document.addEventListener("online", yourCallbackFunction, false); Details

...

function onOnline() {     // Handle the online event }

Similarly for offline

document.addEventListener("offline", yourCallbackFunction, false); Details

...

function onOffline() {     // Handle the offline event } 
1

You can use the new HTML 5 event to detect connectivity. See http://html5demos.com/offline for demo and source.

  • Very cool, didn't know about this, my only question is how could I hook into this to fire my sync once connection is restored? Hopefully something cleaner than just checking on a given interval. – Phil B Jun 18 '14 at 16:40
  • @PhilB It's not an interval: your script will receive an event when connectivity is toggled, much like a mouse click or a key event. There's no monitoring involved. The initial check is to see if you're online during load (because you could be loaded from the cache without connectivity). – sfdcfox Jun 18 '14 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.