简体   繁体   中英

Apache Cordova broadband

I haven't been able to find information about network restrictions and Cordova. My question is How can I prevent or restrict the use of mobile (3G/4G) broadband in a Apache Cordova 5 App?

You could use the following plugin . To check the connection type and act on that connection type. For example:

function checkConnection() {
    var networkState = navigator.connection.type;

    var states = {};
    states[Connection.UNKNOWN]  = 'Unknown connection';
    states[Connection.ETHERNET] = 'Ethernet connection';
    states[Connection.WIFI]     = 'WiFi connection';
    states[Connection.CELL_2G]  = 'Cell 2G connection';
    states[Connection.CELL_3G]  = 'Cell 3G connection';
    states[Connection.CELL_4G]  = 'Cell 4G connection';
    states[Connection.CELL]     = 'Cell generic connection';
    states[Connection.NONE]     = 'No network connection';

    if(!states[Connection.WIFI] || !states[Connection.ETHERNET]) {
        alert('Your current connection type: ' + states[networkState] + ' is not supported in this app!');
        // Execute anything you want
        return;
    }
}

checkConnection();

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