Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Using mozMobileConnections with MNC and MCC to enable app features for specific country/carrier combinations
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.