This is a migrated thread and some comments may be shown as answers.

check connection loop

3 Answers 53 Views
General Discussion
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
André
Top achievements
Rank 1
André asked on 24 Jun 2015, 11:48 AM

Hi, I'm developing a hybrid app and when no connection is detected, it redirect users to a view that should handle offline state.

This is the code, what I'm doing wrong here? because I can't navigate after check the connection with sucess..no error is trhown..just nothing happens..

 CODE:

 

 <div data-role="view" id="vOffline" style="width: 100%; height: 100%" class="blackbg" data-before-show="connectionLoop"></div>

<script>

 function connectionLoop() {

    if (navigator.connection.type != Connection.NONE) {

        kendo.mobile.application.navigate("#home");

       //also does not work using #:back..actually sometimes works and sometimes don't..I can't figure it out why..
        return;
    } else {
        setTimeout(function () {
            navigator.notification.alert("It seems that is no connection available. \nLets try again?", connectionLoop, username, "YEP!");
        }, 500)
    }
}

</script>

3 Answers, 1 is accepted

Sort by
0
André
Top achievements
Rank 1
answered on 24 Jun 2015, 07:17 PM

I've been trying other solutions with no luck..

I think maybe it's because this "offline" view is called after a preventDefault on the initial view of app..

 Somehow I can't navigate out of it...

0
André
Top achievements
Rank 1
answered on 25 Jun 2015, 12:11 AM

yeah, now I'm sure..if I execute e.preventDefault in some view, I  can't navigate to that view anymore using app.navigate..

0
Martin Yankov
Telerik team
answered on 29 Jun 2015, 08:02 AM
Hello Andre,

Firstly, let me clarify that you don't need to use a loop to check connection yourself. If you enable the Network Connection plugin for your project, it provides two events - 'offline' and 'online'. You can simply use them instead of checking yourself every half a second. Here is an example:
document.addEventListener('offline', function () {
    _onConnectionLost();
}, false);

Of course, you need to add this event listener after the deviceready event has fired.

Regarding your problem with the navigation, can you please explain what you mean by "executing e.preventDefault in a view"? Do you mean in any event handler in the view? Can you please provide some code from a view that breaks the navigation, so that I can try to reproduce this?

Thanks in advance for the cooperation.

Regards,
Martin Yankov
Telerik
 

Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

 
Tags
General Discussion
Asked by
André
Top achievements
Rank 1
Answers by
André
Top achievements
Rank 1
Martin Yankov
Telerik team
Share this question
or