Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Using mozMobileConnections with MNC and MCC to enable app features for specific country/carrier combinations

View detectByConnection.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
var mccs = [];
 
try {
// navigator.mozMobileConnections is the new API.
// navigator.mozMobileConnection is the legacy API.
var conn;
if ((conn = navigator.mozMobileConnection)) {
console.log('navigator.mozMobileConnection available');
 
// `MCC`: Mobile Country Code
// `MNC`: Mobile Network Code
// `lastKnownHomeNetwork`: `{MCC}-{MNC}` (SIM's origin)
// `lastKnownNetwork`: `{MCC}-{MNC}` (could be different network if roaming)
var network = (conn.lastKnownHomeNetwork || conn.lastKnownNetwork || '-').split('-');
mcc = network[0];
mnc = network[1];
console.log('MCC = ' + mcc + ', MNC = ' + mnc);
mccs.push([mcc, mnc]);
 
} else if ((conn = navigator.mozMobileConnections)) {
console.log('navigator.mozMobileConnections available');
 
for (var i = 0; i < conn.length; i++) {
var connData = conn[i].data;
if (connData && connData.network) {
mccs.push({
mcc: connData.network.mcc,
mnc: connData.network.mnc
});
}
}
}
} catch (e) {
// Fail gracefully if `navigator.mozMobileConnection` gives us problems.
console.warn('Error accessing navigator.mozMobileConnection:', e);
}
 
var enableApp = false;
 
if (mccs.length) {
// Look up region and carrier from MCC (Mobile Country Code)
// and MNC (Mobile Network Code).
// Codes from https://gist.github.com/digitarald/5717512
// Make your own list, mcc as index and mncs as array
var enabledMccs = {
'732': [123], // Colombia
'734': [4], // Venezuela
'214': [5, 7], // Spain
'724': [6, 10, 11, 23] // Brazil
};
 
// First returned "true" will stop .some iteration
enableApp = mccs.some(function(mccData) {
// Country is in list
var mncs = enabledMccs[mccData.mcc];
// Carrier is in country list
return mncs && (mncs.indexOf(mccData.mnc) >= 0);
});
}
 
if (enableApp) {
App.start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.