简体   繁体   中英

Offline/Online events in ios simulator

I have a phonegap 3.3 application which uses angularjs. I am able to listen for the 'offline' and 'online' events if I run the application in my browser, but when I use the ios (7) simulator I get some strange event sequences, like this:

If I turn wi-fi off, I see the following in my console:

OFFLINE EVENT
ONLINE EVENT

If I then turn wi-fi back on, I see the following sequence:

OFFLINE EVENT
ONLINE EVENT
OFFLINE EVENT
ONLINE EVENT

The event handling code is sitting in app.js:

var app = angular.module('test', []);

app.run(function($window, $rootScope) {
    $rootScope.online = navigator.onLine;

    $window.addEventListener("offline", function () {
        console.log("OFFLINE EVENT");
        $rootScope.$apply(function() {
            $rootScope.online = false;
        });
    }, false);
    $window.addEventListener("online", function () {
        console.log("ONLINE EVENT");
        $rootScope.$apply(function() {
            $rootScope.online = true;
        });
    }, false);
});

The PhoneGap documentation has those events as document.addEventListener. The battery events are the only ones I see using window.

http://docs.phonegap.com/en/3.3.0/cordova_events_events.md.html#online

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM