summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/ios/www/js/lib/etc/sim.js
blob: 19d2e3c360f355d2c982b0e22beef589b44ca5c1 (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
45
46
47
48
49
50
var simcard = (function(){
  var simcard = {}
  
  simcard.loaded = false
  simcard.data = {
    carrierName: 'unknown',
    countryCode: 'us',
    mcc: '0',
    mnc: '0',
  }
  
  simcard.fetch = function(cb){
    console.log('fetching sim data')
    simcard.afterFetch = cb
    window.plugins.sim.getSimInfo(simcard.success, simcard.error)
    // cordova.exec(simcard.success, simcard.error, 'Sim', 'getSimInfo', [])
  }
  
  simcard.afterFetch = function(){}
  
  simcard.success = function(data){
    console.log(data)
    if (simcard.data.countryCode) {
      simcard.data = data
      simcard.data.countryCode = simcard.data.countryCode.toLowerCase()
      // app is only available in US or Canada, so call the US API regardless
      if (simcard.data.countryCode !== 'ca') {
        simcard.data.countryCode = 'us'
      }
    }
    simcard.loaded = true
    simcard.afterFetch()
  }
  
  simcard.error = function(){
    console.log("no SIM card detected")
    $.ajax({
      url: "http://ip-api.com/json/",
      jsonp: "callback",
      dataType: "jsonp",
      success: simcard.success,
      error: function(){
        simcard.loaded = true
        simcard.afterFetch()
      }
    })
  }
  
  return simcard
})()