blob: ca01ddc76a61a478cf663a5b5ae26a27632735ee (
plain)
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
|
var sim = (function(){
var sim = {}
sim.loaded = false
sim.data = {
carrierName: 'unknown',
countryCode: 'us',
mcc: '0',
mnc: '0',
}
sim.fetch = function(cb){
sim.afterFetch = cb
window.plugins.sim.getSimInfo(sim.success, sim.error)
}
sim.afterFetch = function(){}
sim.success = function(data){
console.log(data)
if (sim.data.countryCode) {
sim.data = data
sim.data.countryCode = sim.data.countryCode.toLowerCase()
// app is only available in US or Canada, so call the US API regardless
if (sim.data.countryCode !== 'ca') {
sim.data.countryCode = 'us'
}
}
sim.loaded = true
sim.afterFetch()
}
sim.error = function(){
console.log("no SIM card detected")
$.ajax({
url: "http://ip-api.com/json/",
jsonp: "callback",
dataType: "jsonp",
success: sim.success,
})
}
return sim
})()
|