Page 1 of 1

resume and offline event handling order

Posted: Mon Feb 16, 2015 9:01 pm
by Cody Blue

I handle "resume" (document.addEventListener("resume", onResume , false);) and "offline" events in an Appery project.

It seems the cordova handles resume first and then offline.

However, depending on whether on not the device is connected I need to make decisions within onResume function above. My question is if there is a way for me to detect that device is offline or online while handling the "resume" event?

Suggestions would be appreciated.


resume and offline event handling order

Posted: Mon Feb 16, 2015 10:37 pm
by Illya Stepanov

Hi -

[quote:]However, depending on whether on not the device is connected I need to make decisions within onResume function above. My question is if there is a way for me to detect that device is offline or online while handling the "resume" event? [/quote]
Yes - you can for a example make a dummy request or service call. And handle the events - success or error. If its 'offline' then don't execute the resume event.
pre
code
var onSuccess = function(){
alert("online");
};
var onError = function(){
alert("online");
};

serviceName.execute({success: onSuccess, error: onError});
/code
/pre


resume and offline event handling order

Posted: Tue Feb 17, 2015 1:54 am
by Cody Blue

Thanks for the feedback here. This could be viable, but I am bit concerned that if the error is due to other factors (timeout, etc.) wouldn't the "offline" assumption be invalid?


resume and offline event handling order

Posted: Wed Feb 18, 2015 5:33 am
by Yurii Orishchuk

Hi Cody,

You right, this approach could get a mistake. But online/offline events based on the same mechanism. There is no other way to define is there a connection to external source.

Regards.