List of phone number country codes [closed] - phone-number
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
On this Wikipedia entry I found out that ITU Telecommunication Standardization Sector (ITU-T) is providing such list of country calling codes.
Here is a pdf: http://www.itu.int/dms_pub/itu-t/opb/sp/T-SP-E.164D-2009-PDF-E.pdf
I wonder where to find this in a xml file or similar? I need to do find out which country a phone number is from, both in javascript and c#.
I generated json file in the following format (Hope that it will help you) :
{
"countries": [
{
"code": "+7 840",
"name": "Abkhazia"
},
{
"code": "+93",
"name": "Afghanistan"
},
{
"code": "+355",
"name": "Albania"
},
{
"code": "+213",
"name": "Algeria"
},
{
"code": "+1 684",
"name": "American Samoa"
},
{
"code": "+376",
"name": "Andorra"
},
{
"code": "+244",
"name": "Angola"
},
{
"code": "+1 264",
"name": "Anguilla"
},
{
"code": "+1 268",
"name": "Antigua and Barbuda"
},
{
"code": "+54",
"name": "Argentina"
},
{
"code": "+374",
"name": "Armenia"
},
{
"code": "+297",
"name": "Aruba"
},
{
"code": "+247",
"name": "Ascension"
},
{
"code": "+61",
"name": "Australia"
},
{
"code": "+672",
"name": "Australian External Territories"
},
{
"code": "+43",
"name": "Austria"
},
{
"code": "+994",
"name": "Azerbaijan"
},
{
"code": "+1 242",
"name": "Bahamas"
},
{
"code": "+973",
"name": "Bahrain"
},
{
"code": "+880",
"name": "Bangladesh"
},
{
"code": "+1 246",
"name": "Barbados"
},
{
"code": "+1 268",
"name": "Barbuda"
},
{
"code": "+375",
"name": "Belarus"
},
{
"code": "+32",
"name": "Belgium"
},
{
"code": "+501",
"name": "Belize"
},
{
"code": "+229",
"name": "Benin"
},
{
"code": "+1 441",
"name": "Bermuda"
},
{
"code": "+975",
"name": "Bhutan"
},
{
"code": "+591",
"name": "Bolivia"
},
{
"code": "+387",
"name": "Bosnia and Herzegovina"
},
{
"code": "+267",
"name": "Botswana"
},
{
"code": "+55",
"name": "Brazil"
},
{
"code": "+246",
"name": "British Indian Ocean Territory"
},
{
"code": "+1 284",
"name": "British Virgin Islands"
},
{
"code": "+673",
"name": "Brunei"
},
{
"code": "+359",
"name": "Bulgaria"
},
{
"code": "+226",
"name": "Burkina Faso"
},
{
"code": "+257",
"name": "Burundi"
},
{
"code": "+855",
"name": "Cambodia"
},
{
"code": "+237",
"name": "Cameroon"
},
{
"code": "+1",
"name": "Canada"
},
{
"code": "+238",
"name": "Cape Verde"
},
{
"code": "+ 345",
"name": "Cayman Islands"
},
{
"code": "+236",
"name": "Central African Republic"
},
{
"code": "+235",
"name": "Chad"
},
{
"code": "+56",
"name": "Chile"
},
{
"code": "+86",
"name": "China"
},
{
"code": "+61",
"name": "Christmas Island"
},
{
"code": "+61",
"name": "Cocos-Keeling Islands"
},
{
"code": "+57",
"name": "Colombia"
},
{
"code": "+269",
"name": "Comoros"
},
{
"code": "+242",
"name": "Congo"
},
{
"code": "+243",
"name": "Congo, Dem. Rep. of (Zaire)"
},
{
"code": "+682",
"name": "Cook Islands"
},
{
"code": "+506",
"name": "Costa Rica"
},
{
"code": "+385",
"name": "Croatia"
},
{
"code": "+53",
"name": "Cuba"
},
{
"code": "+599",
"name": "Curacao"
},
{
"code": "+537",
"name": "Cyprus"
},
{
"code": "+420",
"name": "Czech Republic"
},
{
"code": "+45",
"name": "Denmark"
},
{
"code": "+246",
"name": "Diego Garcia"
},
{
"code": "+253",
"name": "Djibouti"
},
{
"code": "+1 767",
"name": "Dominica"
},
{
"code": "+1 809",
"name": "Dominican Republic"
},
{
"code": "+670",
"name": "East Timor"
},
{
"code": "+56",
"name": "Easter Island"
},
{
"code": "+593",
"name": "Ecuador"
},
{
"code": "+20",
"name": "Egypt"
},
{
"code": "+503",
"name": "El Salvador"
},
{
"code": "+240",
"name": "Equatorial Guinea"
},
{
"code": "+291",
"name": "Eritrea"
},
{
"code": "+372",
"name": "Estonia"
},
{
"code": "+251",
"name": "Ethiopia"
},
{
"code": "+500",
"name": "Falkland Islands"
},
{
"code": "+298",
"name": "Faroe Islands"
},
{
"code": "+679",
"name": "Fiji"
},
{
"code": "+358",
"name": "Finland"
},
{
"code": "+33",
"name": "France"
},
{
"code": "+596",
"name": "French Antilles"
},
{
"code": "+594",
"name": "French Guiana"
},
{
"code": "+689",
"name": "French Polynesia"
},
{
"code": "+241",
"name": "Gabon"
},
{
"code": "+220",
"name": "Gambia"
},
{
"code": "+995",
"name": "Georgia"
},
{
"code": "+49",
"name": "Germany"
},
{
"code": "+233",
"name": "Ghana"
},
{
"code": "+350",
"name": "Gibraltar"
},
{
"code": "+30",
"name": "Greece"
},
{
"code": "+299",
"name": "Greenland"
},
{
"code": "+1 473",
"name": "Grenada"
},
{
"code": "+590",
"name": "Guadeloupe"
},
{
"code": "+1 671",
"name": "Guam"
},
{
"code": "+502",
"name": "Guatemala"
},
{
"code": "+224",
"name": "Guinea"
},
{
"code": "+245",
"name": "Guinea-Bissau"
},
{
"code": "+595",
"name": "Guyana"
},
{
"code": "+509",
"name": "Haiti"
},
{
"code": "+504",
"name": "Honduras"
},
{
"code": "+852",
"name": "Hong Kong SAR China"
},
{
"code": "+36",
"name": "Hungary"
},
{
"code": "+354",
"name": "Iceland"
},
{
"code": "+91",
"name": "India"
},
{
"code": "+62",
"name": "Indonesia"
},
{
"code": "+98",
"name": "Iran"
},
{
"code": "+964",
"name": "Iraq"
},
{
"code": "+353",
"name": "Ireland"
},
{
"code": "+972",
"name": "Israel"
},
{
"code": "+39",
"name": "Italy"
},
{
"code": "+225",
"name": "Ivory Coast"
},
{
"code": "+1 876",
"name": "Jamaica"
},
{
"code": "+81",
"name": "Japan"
},
{
"code": "+962",
"name": "Jordan"
},
{
"code": "+7 7",
"name": "Kazakhstan"
},
{
"code": "+254",
"name": "Kenya"
},
{
"code": "+686",
"name": "Kiribati"
},
{
"code": "+965",
"name": "Kuwait"
},
{
"code": "+996",
"name": "Kyrgyzstan"
},
{
"code": "+856",
"name": "Laos"
},
{
"code": "+371",
"name": "Latvia"
},
{
"code": "+961",
"name": "Lebanon"
},
{
"code": "+266",
"name": "Lesotho"
},
{
"code": "+231",
"name": "Liberia"
},
{
"code": "+218",
"name": "Libya"
},
{
"code": "+423",
"name": "Liechtenstein"
},
{
"code": "+370",
"name": "Lithuania"
},
{
"code": "+352",
"name": "Luxembourg"
},
{
"code": "+853",
"name": "Macau SAR China"
},
{
"code": "+389",
"name": "Macedonia"
},
{
"code": "+261",
"name": "Madagascar"
},
{
"code": "+265",
"name": "Malawi"
},
{
"code": "+60",
"name": "Malaysia"
},
{
"code": "+960",
"name": "Maldives"
},
{
"code": "+223",
"name": "Mali"
},
{
"code": "+356",
"name": "Malta"
},
{
"code": "+692",
"name": "Marshall Islands"
},
{
"code": "+596",
"name": "Martinique"
},
{
"code": "+222",
"name": "Mauritania"
},
{
"code": "+230",
"name": "Mauritius"
},
{
"code": "+262",
"name": "Mayotte"
},
{
"code": "+52",
"name": "Mexico"
},
{
"code": "+691",
"name": "Micronesia"
},
{
"code": "+1 808",
"name": "Midway Island"
},
{
"code": "+373",
"name": "Moldova"
},
{
"code": "+377",
"name": "Monaco"
},
{
"code": "+976",
"name": "Mongolia"
},
{
"code": "+382",
"name": "Montenegro"
},
{
"code": "+1664",
"name": "Montserrat"
},
{
"code": "+212",
"name": "Morocco"
},
{
"code": "+95",
"name": "Myanmar"
},
{
"code": "+264",
"name": "Namibia"
},
{
"code": "+674",
"name": "Nauru"
},
{
"code": "+977",
"name": "Nepal"
},
{
"code": "+31",
"name": "Netherlands"
},
{
"code": "+599",
"name": "Netherlands Antilles"
},
{
"code": "+1 869",
"name": "Nevis"
},
{
"code": "+687",
"name": "New Caledonia"
},
{
"code": "+64",
"name": "New Zealand"
},
{
"code": "+505",
"name": "Nicaragua"
},
{
"code": "+227",
"name": "Niger"
},
{
"code": "+234",
"name": "Nigeria"
},
{
"code": "+683",
"name": "Niue"
},
{
"code": "+672",
"name": "Norfolk Island"
},
{
"code": "+850",
"name": "North Korea"
},
{
"code": "+1 670",
"name": "Northern Mariana Islands"
},
{
"code": "+47",
"name": "Norway"
},
{
"code": "+968",
"name": "Oman"
},
{
"code": "+92",
"name": "Pakistan"
},
{
"code": "+680",
"name": "Palau"
},
{
"code": "+970",
"name": "Palestinian Territory"
},
{
"code": "+507",
"name": "Panama"
},
{
"code": "+675",
"name": "Papua New Guinea"
},
{
"code": "+595",
"name": "Paraguay"
},
{
"code": "+51",
"name": "Peru"
},
{
"code": "+63",
"name": "Philippines"
},
{
"code": "+48",
"name": "Poland"
},
{
"code": "+351",
"name": "Portugal"
},
{
"code": "+1 787",
"name": "Puerto Rico"
},
{
"code": "+974",
"name": "Qatar"
},
{
"code": "+262",
"name": "Reunion"
},
{
"code": "+40",
"name": "Romania"
},
{
"code": "+7",
"name": "Russia"
},
{
"code": "+250",
"name": "Rwanda"
},
{
"code": "+685",
"name": "Samoa"
},
{
"code": "+378",
"name": "San Marino"
},
{
"code": "+966",
"name": "Saudi Arabia"
},
{
"code": "+221",
"name": "Senegal"
},
{
"code": "+381",
"name": "Serbia"
},
{
"code": "+248",
"name": "Seychelles"
},
{
"code": "+232",
"name": "Sierra Leone"
},
{
"code": "+65",
"name": "Singapore"
},
{
"code": "+421",
"name": "Slovakia"
},
{
"code": "+386",
"name": "Slovenia"
},
{
"code": "+677",
"name": "Solomon Islands"
},
{
"code": "+27",
"name": "South Africa"
},
{
"code": "+500",
"name": "South Georgia and the South Sandwich Islands"
},
{
"code": "+82",
"name": "South Korea"
},
{
"code": "+34",
"name": "Spain"
},
{
"code": "+94",
"name": "Sri Lanka"
},
{
"code": "+249",
"name": "Sudan"
},
{
"code": "+597",
"name": "Suriname"
},
{
"code": "+268",
"name": "Swaziland"
},
{
"code": "+46",
"name": "Sweden"
},
{
"code": "+41",
"name": "Switzerland"
},
{
"code": "+963",
"name": "Syria"
},
{
"code": "+886",
"name": "Taiwan"
},
{
"code": "+992",
"name": "Tajikistan"
},
{
"code": "+255",
"name": "Tanzania"
},
{
"code": "+66",
"name": "Thailand"
},
{
"code": "+670",
"name": "Timor Leste"
},
{
"code": "+228",
"name": "Togo"
},
{
"code": "+690",
"name": "Tokelau"
},
{
"code": "+676",
"name": "Tonga"
},
{
"code": "+1 868",
"name": "Trinidad and Tobago"
},
{
"code": "+216",
"name": "Tunisia"
},
{
"code": "+90",
"name": "Turkey"
},
{
"code": "+993",
"name": "Turkmenistan"
},
{
"code": "+1 649",
"name": "Turks and Caicos Islands"
},
{
"code": "+688",
"name": "Tuvalu"
},
{
"code": "+1 340",
"name": "U.S. Virgin Islands"
},
{
"code": "+256",
"name": "Uganda"
},
{
"code": "+380",
"name": "Ukraine"
},
{
"code": "+971",
"name": "United Arab Emirates"
},
{
"code": "+44",
"name": "United Kingdom"
},
{
"code": "+1",
"name": "United States"
},
{
"code": "+598",
"name": "Uruguay"
},
{
"code": "+998",
"name": "Uzbekistan"
},
{
"code": "+678",
"name": "Vanuatu"
},
{
"code": "+58",
"name": "Venezuela"
},
{
"code": "+84",
"name": "Vietnam"
},
{
"code": "+1 808",
"name": "Wake Island"
},
{
"code": "+681",
"name": "Wallis and Futuna"
},
{
"code": "+967",
"name": "Yemen"
},
{
"code": "+260",
"name": "Zambia"
},
{
"code": "+255",
"name": "Zanzibar"
},
{
"code": "+263",
"name": "Zimbabwe"
}
]
}
You can get a JSON file that maps country codes to phone codes from http://country.io/phone.json:
...
BD: "880",
BE: "32",
BF: "226",
BG: "359",
BA: "387",
...
If you want country names then http://country.io/names.json will give you that:
...
"AL": "Albania",
"AM": "Armenia",
"AO": "Angola",
"AQ": "Antarctica",
"AR": "Argentina",
...
See http://country.io/data for more details.
There is an Excel file with regexps here. You can easily "convert" it to XML and you will be able to determine country by the full phone number.
UPD: The file that I referenced 4 years ago is no longer accessible. I would recommend using Google's libphonenumber.
The answer to Extract code country from phone number [libphonenumber] will show you the proper way to receive country code from a phone number.
There is a fairly well maintained repo on github that has a CSV (with semicolon delimiters), XML, and JSON source of countries, country codes, and other information.
Rather than trying to roll your own logic for determining the country code of a phone number, I highly recommend using Google's libphonenumber project. This project is very extensive and well maintained, and has been ported to a several languages.
You can easily convert to xml format using online converters:
I have converted the list:
<?xml version="1.0" encoding="UTF-8" ?>
<countries>
<code>+7 840</code>
<name>Abkhazia</name>
</countries>
<countries>
<code>+93</code>
<name>Afghanistan</name>
</countries>
<countries>
<code>+355</code>
<name>Albania</name>
</countries>
<countries>
<code>+213</code>
<name>Algeria</name>
</countries>
<countries>
<code>+1 684</code>
<name>American Samoa</name>
</countries>
<countries>
<code>+376</code>
<name>Andorra</name>
</countries>
<countries>
<code>+244</code>
<name>Angola</name>
</countries>
<countries>
<code>+1 264</code>
<name>Anguilla</name>
</countries>
<countries>
<code>+1 268</code>
<name>Antigua and Barbuda</name>
</countries>
<countries>
<code>+54</code>
<name>Argentina</name>
</countries>
<countries>
<code>+374</code>
<name>Armenia</name>
</countries>
<countries>
<code>+297</code>
<name>Aruba</name>
</countries>
<countries>
<code>+247</code>
<name>Ascension</name>
</countries>
<countries>
<code>+61</code>
<name>Australia</name>
</countries>
<countries>
<code>+672</code>
<name>Australian External Territories</name>
</countries>
<countries>
<code>+43</code>
<name>Austria</name>
</countries>
<countries>
<code>+994</code>
<name>Azerbaijan</name>
</countries>
<countries>
<code>+1 242</code>
<name>Bahamas</name>
</countries>
<countries>
<code>+973</code>
<name>Bahrain</name>
</countries>
<countries>
<code>+880</code>
<name>Bangladesh</name>
</countries>
<countries>
<code>+1 246</code>
<name>Barbados</name>
</countries>
<countries>
<code>+1 268</code>
<name>Barbuda</name>
</countries>
<countries>
<code>+375</code>
<name>Belarus</name>
</countries>
<countries>
<code>+32</code>
<name>Belgium</name>
</countries>
<countries>
<code>+501</code>
<name>Belize</name>
</countries>
<countries>
<code>+229</code>
<name>Benin</name>
</countries>
<countries>
<code>+1 441</code>
<name>Bermuda</name>
</countries>
<countries>
<code>+975</code>
<name>Bhutan</name>
</countries>
<countries>
<code>+591</code>
<name>Bolivia</name>
</countries>
<countries>
<code>+387</code>
<name>Bosnia and Herzegovina</name>
</countries>
<countries>
<code>+267</code>
<name>Botswana</name>
</countries>
<countries>
<code>+55</code>
<name>Brazil</name>
</countries>
<countries>
<code>+246</code>
<name>British Indian Ocean Territory</name>
</countries>
<countries>
<code>+1 284</code>
<name>British Virgin Islands</name>
</countries>
<countries>
<code>+673</code>
<name>Brunei</name>
</countries>
<countries>
<code>+359</code>
<name>Bulgaria</name>
</countries>
<countries>
<code>+226</code>
<name>Burkina Faso</name>
</countries>
<countries>
<code>+257</code>
<name>Burundi</name>
</countries>
<countries>
<code>+855</code>
<name>Cambodia</name>
</countries>
<countries>
<code>+237</code>
<name>Cameroon</name>
</countries>
<countries>
<code>+1</code>
<name>Canada</name>
</countries>
<countries>
<code>+238</code>
<name>Cape Verde</name>
</countries>
<countries>
<code>+ 345</code>
<name>Cayman Islands</name>
</countries>
<countries>
<code>+236</code>
<name>Central African Republic</name>
</countries>
<countries>
<code>+235</code>
<name>Chad</name>
</countries>
<countries>
<code>+56</code>
<name>Chile</name>
</countries>
<countries>
<code>+86</code>
<name>China</name>
</countries>
<countries>
<code>+61</code>
<name>Christmas Island</name>
</countries>
<countries>
<code>+61</code>
<name>Cocos-Keeling Islands</name>
</countries>
<countries>
<code>+57</code>
<name>Colombia</name>
</countries>
<countries>
<code>+269</code>
<name>Comoros</name>
</countries>
<countries>
<code>+242</code>
<name>Congo</name>
</countries>
<countries>
<code>+243</code>
<name>Congo, Dem. Rep. of (Zaire)</name>
</countries>
<countries>
<code>+682</code>
<name>Cook Islands</name>
</countries>
<countries>
<code>+506</code>
<name>Costa Rica</name>
</countries>
<countries>
<code>+385</code>
<name>Croatia</name>
</countries>
<countries>
<code>+53</code>
<name>Cuba</name>
</countries>
<countries>
<code>+599</code>
<name>Curacao</name>
</countries>
<countries>
<code>+537</code>
<name>Cyprus</name>
</countries>
<countries>
<code>+420</code>
<name>Czech Republic</name>
</countries>
<countries>
<code>+45</code>
<name>Denmark</name>
</countries>
<countries>
<code>+246</code>
<name>Diego Garcia</name>
</countries>
<countries>
<code>+253</code>
<name>Djibouti</name>
</countries>
<countries>
<code>+1 767</code>
<name>Dominica</name>
</countries>
<countries>
<code>+1 809</code>
<name>Dominican Republic</name>
</countries>
<countries>
<code>+670</code>
<name>East Timor</name>
</countries>
<countries>
<code>+56</code>
<name>Easter Island</name>
</countries>
<countries>
<code>+593</code>
<name>Ecuador</name>
</countries>
<countries>
<code>+20</code>
<name>Egypt</name>
</countries>
<countries>
<code>+503</code>
<name>El Salvador</name>
</countries>
<countries>
<code>+240</code>
<name>Equatorial Guinea</name>
</countries>
<countries>
<code>+291</code>
<name>Eritrea</name>
</countries>
<countries>
<code>+372</code>
<name>Estonia</name>
</countries>
<countries>
<code>+251</code>
<name>Ethiopia</name>
</countries>
<countries>
<code>+500</code>
<name>Falkland Islands</name>
</countries>
<countries>
<code>+298</code>
<name>Faroe Islands</name>
</countries>
<countries>
<code>+679</code>
<name>Fiji</name>
</countries>
<countries>
<code>+358</code>
<name>Finland</name>
</countries>
<countries>
<code>+33</code>
<name>France</name>
</countries>
<countries>
<code>+596</code>
<name>French Antilles</name>
</countries>
<countries>
<code>+594</code>
<name>French Guiana</name>
</countries>
<countries>
<code>+689</code>
<name>French Polynesia</name>
</countries>
<countries>
<code>+241</code>
<name>Gabon</name>
</countries>
<countries>
<code>+220</code>
<name>Gambia</name>
</countries>
<countries>
<code>+995</code>
<name>Georgia</name>
</countries>
<countries>
<code>+49</code>
<name>Germany</name>
</countries>
<countries>
<code>+233</code>
<name>Ghana</name>
</countries>
<countries>
<code>+350</code>
<name>Gibraltar</name>
</countries>
<countries>
<code>+30</code>
<name>Greece</name>
</countries>
<countries>
<code>+299</code>
<name>Greenland</name>
</countries>
<countries>
<code>+1 473</code>
<name>Grenada</name>
</countries>
<countries>
<code>+590</code>
<name>Guadeloupe</name>
</countries>
<countries>
<code>+1 671</code>
<name>Guam</name>
</countries>
<countries>
<code>+502</code>
<name>Guatemala</name>
</countries>
<countries>
<code>+224</code>
<name>Guinea</name>
</countries>
<countries>
<code>+245</code>
<name>Guinea-Bissau</name>
</countries>
<countries>
<code>+595</code>
<name>Guyana</name>
</countries>
<countries>
<code>+509</code>
<name>Haiti</name>
</countries>
<countries>
<code>+504</code>
<name>Honduras</name>
</countries>
<countries>
<code>+852</code>
<name>Hong Kong SAR China</name>
</countries>
<countries>
<code>+36</code>
<name>Hungary</name>
</countries>
<countries>
<code>+354</code>
<name>Iceland</name>
</countries>
<countries>
<code>+91</code>
<name>India</name>
</countries>
<countries>
<code>+62</code>
<name>Indonesia</name>
</countries>
<countries>
<code>+98</code>
<name>Iran</name>
</countries>
<countries>
<code>+964</code>
<name>Iraq</name>
</countries>
<countries>
<code>+353</code>
<name>Ireland</name>
</countries>
<countries>
<code>+972</code>
<name>Israel</name>
</countries>
<countries>
<code>+39</code>
<name>Italy</name>
</countries>
<countries>
<code>+225</code>
<name>Ivory Coast</name>
</countries>
<countries>
<code>+1 876</code>
<name>Jamaica</name>
</countries>
<countries>
<code>+81</code>
<name>Japan</name>
</countries>
<countries>
<code>+962</code>
<name>Jordan</name>
</countries>
<countries>
<code>+7 7</code>
<name>Kazakhstan</name>
</countries>
<countries>
<code>+254</code>
<name>Kenya</name>
</countries>
<countries>
<code>+686</code>
<name>Kiribati</name>
</countries>
<countries>
<code>+965</code>
<name>Kuwait</name>
</countries>
<countries>
<code>+996</code>
<name>Kyrgyzstan</name>
</countries>
<countries>
<code>+856</code>
<name>Laos</name>
</countries>
<countries>
<code>+371</code>
<name>Latvia</name>
</countries>
<countries>
<code>+961</code>
<name>Lebanon</name>
</countries>
<countries>
<code>+266</code>
<name>Lesotho</name>
</countries>
<countries>
<code>+231</code>
<name>Liberia</name>
</countries>
<countries>
<code>+218</code>
<name>Libya</name>
</countries>
<countries>
<code>+423</code>
<name>Liechtenstein</name>
</countries>
<countries>
<code>+370</code>
<name>Lithuania</name>
</countries>
<countries>
<code>+352</code>
<name>Luxembourg</name>
</countries>
<countries>
<code>+853</code>
<name>Macau SAR China</name>
</countries>
<countries>
<code>+389</code>
<name>Macedonia</name>
</countries>
<countries>
<code>+261</code>
<name>Madagascar</name>
</countries>
<countries>
<code>+265</code>
<name>Malawi</name>
</countries>
<countries>
<code>+60</code>
<name>Malaysia</name>
</countries>
<countries>
<code>+960</code>
<name>Maldives</name>
</countries>
<countries>
<code>+223</code>
<name>Mali</name>
</countries>
<countries>
<code>+356</code>
<name>Malta</name>
</countries>
<countries>
<code>+692</code>
<name>Marshall Islands</name>
</countries>
<countries>
<code>+596</code>
<name>Martinique</name>
</countries>
<countries>
<code>+222</code>
<name>Mauritania</name>
</countries>
<countries>
<code>+230</code>
<name>Mauritius</name>
</countries>
<countries>
<code>+262</code>
<name>Mayotte</name>
</countries>
<countries>
<code>+52</code>
<name>Mexico</name>
</countries>
<countries>
<code>+691</code>
<name>Micronesia</name>
</countries>
<countries>
<code>+1 808</code>
<name>Midway Island</name>
</countries>
<countries>
<code>+373</code>
<name>Moldova</name>
</countries>
<countries>
<code>+377</code>
<name>Monaco</name>
</countries>
<countries>
<code>+976</code>
<name>Mongolia</name>
</countries>
<countries>
<code>+382</code>
<name>Montenegro</name>
</countries>
<countries>
<code>+1664</code>
<name>Montserrat</name>
</countries>
<countries>
<code>+212</code>
<name>Morocco</name>
</countries>
<countries>
<code>+95</code>
<name>Myanmar</name>
</countries>
<countries>
<code>+264</code>
<name>Namibia</name>
</countries>
<countries>
<code>+674</code>
<name>Nauru</name>
</countries>
<countries>
<code>+977</code>
<name>Nepal</name>
</countries>
<countries>
<code>+31</code>
<name>Netherlands</name>
</countries>
<countries>
<code>+599</code>
<name>Netherlands Antilles</name>
</countries>
<countries>
<code>+1 869</code>
<name>Nevis</name>
</countries>
<countries>
<code>+687</code>
<name>New Caledonia</name>
</countries>
<countries>
<code>+64</code>
<name>New Zealand</name>
</countries>
<countries>
<code>+505</code>
<name>Nicaragua</name>
</countries>
<countries>
<code>+227</code>
<name>Niger</name>
</countries>
<countries>
<code>+234</code>
<name>Nigeria</name>
</countries>
<countries>
<code>+683</code>
<name>Niue</name>
</countries>
<countries>
<code>+672</code>
<name>Norfolk Island</name>
</countries>
<countries>
<code>+850</code>
<name>North Korea</name>
</countries>
<countries>
<code>+1 670</code>
<name>Northern Mariana Islands</name>
</countries>
<countries>
<code>+47</code>
<name>Norway</name>
</countries>
<countries>
<code>+968</code>
<name>Oman</name>
</countries>
<countries>
<code>+92</code>
<name>Pakistan</name>
</countries>
<countries>
<code>+680</code>
<name>Palau</name>
</countries>
<countries>
<code>+970</code>
<name>Palestinian Territory</name>
</countries>
<countries>
<code>+507</code>
<name>Panama</name>
</countries>
<countries>
<code>+675</code>
<name>Papua New Guinea</name>
</countries>
<countries>
<code>+595</code>
<name>Paraguay</name>
</countries>
<countries>
<code>+51</code>
<name>Peru</name>
</countries>
<countries>
<code>+63</code>
<name>Philippines</name>
</countries>
<countries>
<code>+48</code>
<name>Poland</name>
</countries>
<countries>
<code>+351</code>
<name>Portugal</name>
</countries>
<countries>
<code>+1 787</code>
<name>Puerto Rico</name>
</countries>
<countries>
<code>+974</code>
<name>Qatar</name>
</countries>
<countries>
<code>+262</code>
<name>Reunion</name>
</countries>
<countries>
<code>+40</code>
<name>Romania</name>
</countries>
<countries>
<code>+7</code>
<name>Russia</name>
</countries>
<countries>
<code>+250</code>
<name>Rwanda</name>
</countries>
<countries>
<code>+685</code>
<name>Samoa</name>
</countries>
<countries>
<code>+378</code>
<name>San Marino</name>
</countries>
<countries>
<code>+966</code>
<name>Saudi Arabia</name>
</countries>
<countries>
<code>+221</code>
<name>Senegal</name>
</countries>
<countries>
<code>+381</code>
<name>Serbia</name>
</countries>
<countries>
<code>+248</code>
<name>Seychelles</name>
</countries>
<countries>
<code>+232</code>
<name>Sierra Leone</name>
</countries>
<countries>
<code>+65</code>
<name>Singapore</name>
</countries>
<countries>
<code>+421</code>
<name>Slovakia</name>
</countries>
<countries>
<code>+386</code>
<name>Slovenia</name>
</countries>
<countries>
<code>+677</code>
<name>Solomon Islands</name>
</countries>
<countries>
<code>+27</code>
<name>South Africa</name>
</countries>
<countries>
<code>+500</code>
<name>South Georgia and the South Sandwich Islands</name>
</countries>
<countries>
<code>+82</code>
<name>South Korea</name>
</countries>
<countries>
<code>+34</code>
<name>Spain</name>
</countries>
<countries>
<code>+94</code>
<name>Sri Lanka</name>
</countries>
<countries>
<code>+249</code>
<name>Sudan</name>
</countries>
<countries>
<code>+597</code>
<name>Suriname</name>
</countries>
<countries>
<code>+268</code>
<name>Swaziland</name>
</countries>
<countries>
<code>+46</code>
<name>Sweden</name>
</countries>
<countries>
<code>+41</code>
<name>Switzerland</name>
</countries>
<countries>
<code>+963</code>
<name>Syria</name>
</countries>
<countries>
<code>+886</code>
<name>Taiwan</name>
</countries>
<countries>
<code>+992</code>
<name>Tajikistan</name>
</countries>
<countries>
<code>+255</code>
<name>Tanzania</name>
</countries>
<countries>
<code>+66</code>
<name>Thailand</name>
</countries>
<countries>
<code>+670</code>
<name>Timor Leste</name>
</countries>
<countries>
<code>+228</code>
<name>Togo</name>
</countries>
<countries>
<code>+690</code>
<name>Tokelau</name>
</countries>
<countries>
<code>+676</code>
<name>Tonga</name>
</countries>
<countries>
<code>+1 868</code>
<name>Trinidad and Tobago</name>
</countries>
<countries>
<code>+216</code>
<name>Tunisia</name>
</countries>
<countries>
<code>+90</code>
<name>Turkey</name>
</countries>
<countries>
<code>+993</code>
<name>Turkmenistan</name>
</countries>
<countries>
<code>+1 649</code>
<name>Turks and Caicos Islands</name>
</countries>
<countries>
<code>+688</code>
<name>Tuvalu</name>
</countries>
<countries>
<code>+1 340</code>
<name>U.S. Virgin Islands</name>
</countries>
<countries>
<code>+256</code>
<name>Uganda</name>
</countries>
<countries>
<code>+380</code>
<name>Ukraine</name>
</countries>
<countries>
<code>+971</code>
<name>United Arab Emirates</name>
</countries>
<countries>
<code>+44</code>
<name>United Kingdom</name>
</countries>
<countries>
<code>+1</code>
<name>United States</name>
</countries>
<countries>
<code>+598</code>
<name>Uruguay</name>
</countries>
<countries>
<code>+998</code>
<name>Uzbekistan</name>
</countries>
<countries>
<code>+678</code>
<name>Vanuatu</name>
</countries>
<countries>
<code>+58</code>
<name>Venezuela</name>
</countries>
<countries>
<code>+84</code>
<name>Vietnam</name>
</countries>
<countries>
<code>+1 808</code>
<name>Wake Island</name>
</countries>
<countries>
<code>+681</code>
<name>Wallis and Futuna</name>
</countries>
<countries>
<code>+967</code>
<name>Yemen</name>
</countries>
<countries>
<code>+260</code>
<name>Zambia</name>
</countries>
<countries>
<code>+255</code>
<name>Zanzibar</name>
</countries>
<countries>
<code>+263</code>
<name>Zimbabwe</name>
</countries>
Here is a JS function that converts "Country Code" (ISO3) to Telephone "Calling Code":
function country_iso3_to_country_calling_code(country_iso3) {
if(country_iso3 == 'AFG') return '93';
if(country_iso3 == 'ALB') return '355';
if(country_iso3 == 'DZA') return '213';
if(country_iso3 == 'ASM') return '1684';
if(country_iso3 == 'AND') return '376';
if(country_iso3 == 'AGO') return '244';
if(country_iso3 == 'AIA') return '1264';
if(country_iso3 == 'ATA') return '672';
if(country_iso3 == 'ATG') return '1268';
if(country_iso3 == 'ARG') return '54';
if(country_iso3 == 'ARM') return '374';
if(country_iso3 == 'ABW') return '297';
if(country_iso3 == 'AUS') return '61';
if(country_iso3 == 'AUT') return '43';
if(country_iso3 == 'AZE') return '994';
if(country_iso3 == 'BHS') return '1242';
if(country_iso3 == 'BHR') return '973';
if(country_iso3 == 'BGD') return '880';
if(country_iso3 == 'BRB') return '1246';
if(country_iso3 == 'BLR') return '375';
if(country_iso3 == 'BEL') return '32';
if(country_iso3 == 'BLZ') return '501';
if(country_iso3 == 'BEN') return '229';
if(country_iso3 == 'BMU') return '1441';
if(country_iso3 == 'BTN') return '975';
if(country_iso3 == 'BOL') return '591';
if(country_iso3 == 'BIH') return '387';
if(country_iso3 == 'BWA') return '267';
if(country_iso3 == 'BVT') return '_55';
if(country_iso3 == 'BRA') return '55';
if(country_iso3 == 'IOT') return '1284';
if(country_iso3 == 'BRN') return '673';
if(country_iso3 == 'BGR') return '359';
if(country_iso3 == 'BFA') return '226';
if(country_iso3 == 'BDI') return '257';
if(country_iso3 == 'KHM') return '855';
if(country_iso3 == 'CMR') return '237';
if(country_iso3 == 'CAN') return '1';
if(country_iso3 == 'CPV') return '238';
if(country_iso3 == 'CYM') return '1345';
if(country_iso3 == 'CAF') return '236';
if(country_iso3 == 'TCD') return '235';
if(country_iso3 == 'CHL') return '56';
if(country_iso3 == 'CHN') return '86';
if(country_iso3 == 'CXR') return '618';
if(country_iso3 == 'CCK') return '61';
if(country_iso3 == 'COL') return '57';
if(country_iso3 == 'COM') return '269';
if(country_iso3 == 'COG') return '242';
if(country_iso3 == 'COD') return '243';
if(country_iso3 == 'COK') return '682';
if(country_iso3 == 'CRI') return '506';
if(country_iso3 == 'HRV') return '385';
if(country_iso3 == 'CUB') return '53';
if(country_iso3 == 'CYP') return '357';
if(country_iso3 == 'CZE') return '420';
if(country_iso3 == 'DNK') return '45';
if(country_iso3 == 'DJI') return '253';
if(country_iso3 == 'DMA') return '1767';
if(country_iso3 == 'DOM') return '1';
if(country_iso3 == 'ECU') return '593';
if(country_iso3 == 'EGY') return '20';
if(country_iso3 == 'SLV') return '503';
if(country_iso3 == 'GNQ') return '240';
if(country_iso3 == 'ERI') return '291';
if(country_iso3 == 'EST') return '372';
if(country_iso3 == 'ETH') return '251';
if(country_iso3 == 'FLK') return '500';
if(country_iso3 == 'FRO') return '298';
if(country_iso3 == 'FJI') return '679';
if(country_iso3 == 'FIN') return '358';
if(country_iso3 == 'FRA') return '33';
if(country_iso3 == 'GUF') return '594';
if(country_iso3 == 'PYF') return '689';
if(country_iso3 == 'GAB') return '241';
if(country_iso3 == 'GMB') return '220';
if(country_iso3 == 'GEO') return '995';
if(country_iso3 == 'DEU') return '49';
if(country_iso3 == 'GHA') return '233';
if(country_iso3 == 'GIB') return '350';
if(country_iso3 == 'GRC') return '30';
if(country_iso3 == 'GRL') return '299';
if(country_iso3 == 'GRD') return '1473';
if(country_iso3 == 'GLP') return '590';
if(country_iso3 == 'GUM') return '1671';
if(country_iso3 == 'GTM') return '502';
if(country_iso3 == 'GIN') return '224';
if(country_iso3 == 'GNB') return '245';
if(country_iso3 == 'GUY') return '592';
if(country_iso3 == 'HTI') return '509';
if(country_iso3 == 'HMD') return '61';
if(country_iso3 == 'VAT') return '3';
if(country_iso3 == 'HND') return '504';
if(country_iso3 == 'HKG') return '852';
if(country_iso3 == 'HUN') return '36';
if(country_iso3 == 'ISL') return '354';
if(country_iso3 == 'IND') return '91';
if(country_iso3 == 'IDN') return '62';
if(country_iso3 == 'IRN') return '98';
if(country_iso3 == 'IRQ') return '964';
if(country_iso3 == 'IRL') return '353';
if(country_iso3 == 'ISR') return '972';
if(country_iso3 == 'ITA') return '39';
if(country_iso3 == 'CIV') return '225';
if(country_iso3 == 'JAM') return '1876';
if(country_iso3 == 'JPN') return '81';
if(country_iso3 == 'JOR') return '962';
if(country_iso3 == 'KAZ') return '7';
if(country_iso3 == 'KEN') return '254';
if(country_iso3 == 'KIR') return '686';
if(country_iso3 == 'PRK') return '850';
if(country_iso3 == 'KOR') return '82';
if(country_iso3 == 'KWT') return '965';
if(country_iso3 == 'KGZ') return '7';
if(country_iso3 == 'LAO') return '856';
if(country_iso3 == 'LVA') return '371';
if(country_iso3 == 'LBN') return '961';
if(country_iso3 == 'LSO') return '266';
if(country_iso3 == 'LBR') return '231';
if(country_iso3 == 'LBY') return '218';
if(country_iso3 == 'LIE') return '423';
if(country_iso3 == 'LTU') return '370';
if(country_iso3 == 'LUX') return '352';
if(country_iso3 == 'MAC') return '853';
if(country_iso3 == 'MKD') return '389';
if(country_iso3 == 'MDG') return '261';
if(country_iso3 == 'MWI') return '265';
if(country_iso3 == 'MYS') return '60';
if(country_iso3 == 'MDV') return '960';
if(country_iso3 == 'MLI') return '223';
if(country_iso3 == 'MLT') return '356';
if(country_iso3 == 'MHL') return '692';
if(country_iso3 == 'MTQ') return '596';
if(country_iso3 == 'MRT') return '222';
if(country_iso3 == 'MUS') return '230';
if(country_iso3 == 'MYT') return '262';
if(country_iso3 == 'MEX') return '52';
if(country_iso3 == 'FSM') return '691';
if(country_iso3 == 'MDA') return '373';
if(country_iso3 == 'MCO') return '377';
if(country_iso3 == 'MNG') return '976';
if(country_iso3 == 'MSR') return '1664';
if(country_iso3 == 'MAR') return '212';
if(country_iso3 == 'MOZ') return '258';
if(country_iso3 == 'MMR') return '95';
if(country_iso3 == 'NAM') return '264';
if(country_iso3 == 'NRU') return '674';
if(country_iso3 == 'NPL') return '977';
if(country_iso3 == 'NLD') return '31';
if(country_iso3 == 'ANT') return '599';
if(country_iso3 == 'NCL') return '687';
if(country_iso3 == 'NZL') return '64';
if(country_iso3 == 'NIC') return '505';
if(country_iso3 == 'NER') return '227';
if(country_iso3 == 'NGA') return '234';
if(country_iso3 == 'NIU') return '683';
if(country_iso3 == 'NFK') return '672';
if(country_iso3 == 'MNP') return '1670';
if(country_iso3 == 'NOR') return '47';
if(country_iso3 == 'OMN') return '968';
if(country_iso3 == 'PAK') return '92';
if(country_iso3 == 'PLW') return '680';
if(country_iso3 == 'PSE') return '970';
if(country_iso3 == 'PAN') return '507';
if(country_iso3 == 'PNG') return '675';
if(country_iso3 == 'PRY') return '595';
if(country_iso3 == 'PER') return '51';
if(country_iso3 == 'PHL') return '63';
if(country_iso3 == 'PCN') return '870';
if(country_iso3 == 'POL') return '48';
if(country_iso3 == 'PRT') return '351';
if(country_iso3 == 'PRI') return '1';
if(country_iso3 == 'QAT') return '974';
if(country_iso3 == 'REU') return '262';
if(country_iso3 == 'ROM') return '40';
if(country_iso3 == 'RUS') return '7';
if(country_iso3 == 'RWA') return '250';
if(country_iso3 == 'SHN') return '290';
if(country_iso3 == 'KNA') return '1869';
if(country_iso3 == 'LCA') return '1758';
if(country_iso3 == 'SPM') return '508';
if(country_iso3 == 'VCT') return '1758';
if(country_iso3 == 'WSM') return '685';
if(country_iso3 == 'SMR') return '378';
if(country_iso3 == 'STP') return '239';
if(country_iso3 == 'SAU') return '966';
if(country_iso3 == 'SEN') return '221';
if(country_iso3 == 'SRB') return '381';
if(country_iso3 == 'SYC') return '248';
if(country_iso3 == 'SLE') return '232';
if(country_iso3 == 'SGP') return '65';
if(country_iso3 == 'SVK') return '421';
if(country_iso3 == 'SVN') return '386';
if(country_iso3 == 'SLB') return '677';
if(country_iso3 == 'SOM') return '252';
if(country_iso3 == 'ZAF') return '27';
if(country_iso3 == 'SGS') return '44';
if(country_iso3 == 'ESP') return '34';
if(country_iso3 == 'LKA') return '94';
if(country_iso3 == 'SDN') return '249';
if(country_iso3 == 'SUR') return '597';
if(country_iso3 == 'SJM') return '47';
if(country_iso3 == 'SWZ') return '268';
if(country_iso3 == 'SWE') return '46';
if(country_iso3 == 'CHE') return '41';
if(country_iso3 == 'SYR') return '963';
if(country_iso3 == 'TWN') return '886';
if(country_iso3 == 'TJK') return '992';
if(country_iso3 == 'TZA') return '255';
if(country_iso3 == 'THA') return '66';
if(country_iso3 == 'TLS') return '670';
if(country_iso3 == 'TGO') return '228';
if(country_iso3 == 'TKL') return '690';
if(country_iso3 == 'TON') return '676';
if(country_iso3 == 'TTO') return '1868';
if(country_iso3 == 'TUN') return '216';
if(country_iso3 == 'TUR') return '90';
if(country_iso3 == 'TKM') return '993';
if(country_iso3 == 'TCA') return '1649';
if(country_iso3 == 'TUV') return '688';
if(country_iso3 == 'UGA') return '256';
if(country_iso3 == 'UKR') return '380';
if(country_iso3 == 'ARE') return '971';
if(country_iso3 == 'GBR') return '44';
if(country_iso3 == 'USA') return '1';
if(country_iso3 == 'UMI') return '1340';
if(country_iso3 == 'URY') return '598';
if(country_iso3 == 'UZB') return '998';
if(country_iso3 == 'VUT') return '678';
if(country_iso3 == 'VEN') return '58';
if(country_iso3 == 'VNM') return '84';
if(country_iso3 == 'VGB') return '1284';
if(country_iso3 == 'VIR') return '1340';
if(country_iso3 == 'WLF') return '681';
if(country_iso3 == 'YEM') return '260';
if(country_iso3 == 'ZMB') return '260';
if(country_iso3 == 'ZWE') return '263';
}
Android ready county list and flag images
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- country list -->
<string-array name="data000">
<item name="code">+93</item>
<item name="country">Afghanistan</item>
<item name="iso">AF</item>
<item name="flag">#drawable/afghanistan</item>
</string-array>
<string-array name="data001">
<item name="code">+355</item>
<item name="country">Albania</item>
<item name="iso">AL</item>
<item name="flag">#drawable/albania</item>
</string-array>
...
<array name="countries">
<item>#array/data000</item>
<item>#array/data001</item>
...
</array>
</resources>
Country Data NPM Package.
If you're using node or NPM in general, you should take a look at the thorough Country Data package.
Since you're trying to get the Country from a phone number, you face two major obstacles:
Parsing the phone number to get the Country code.
Handling situations where a Country code can belong to more than one Country. e.g. Country Code of "+1" belongs to the United States and Canada.
However, the Country Data package will allow you to do something like this:
var CountryDataLookup = require('country-data').lookup;
lookup.countries({countryCallingCodes: '+1'})
And these are the returning objects:
[ { alpha2: 'CA',
alpha3: 'CAN',
countryCallingCodes: [ '+1' ],
currencies: [ 'CAD' ],
ioc: 'CAN',
languages: [ 'eng', 'fra' ],
name: 'Canada',
status: 'assigned' },
{ alpha2: 'UM',
alpha3: 'UMI',
countryCallingCodes: [ '+1' ],
currencies: [ 'USD' ],
ioc: '',
languages: [ 'eng' ],
name: 'United States Minor Outlying Islands',
status: 'assigned' },
{ alpha2: 'US',
alpha3: 'USA',
countryCallingCodes: [ '+1' ],
currencies: [ 'USD' ],
ioc: 'USA',
languages: [ 'eng' ],
name: 'United States',
status: 'assigned' } ]
I prefer constructed data than third party libraries for many reasons and moreover these data are constants. So generated this json for my purpose. Might be useful for everyone.
Sample Data Format
[
{
"continent_name": "Europe",
"country_code": "AD",
"country_name": "Andorra",
"continent_code": "EU",
"capital_name": "Andorra la Vella",
"currency_code": "EUR",
"phone_code": "376",
"three_letter_country_code": "AND"
},
{
"continent_name": "Asia",
"country_code": "AE",
"country_name": "United Arab Emirates",
"continent_code": "AS",
"capital_name": "Abu Dhabi",
"currency_code": "AED",
"phone_code": "971",
"three_letter_country_code": "ARE"
},
{
"continent_name": "Asia",
"country_code": "AF",
"country_name": "Afghanistan",
"continent_code": "AS",
"capital_name": "Kabul",
"currency_code": "AFN",
"phone_code": "93",
"three_letter_country_code": "AFG"
}
]
No of Countries in the file - 249
Sources
http://country.io/data/
https://datahub.io/JohnSnowLabs/country-and-continent-codes-list#data
Cheers!
Related
Why does this .indexOn: 'g' no longer work as it should?
I can no longer place activeDrivers in the correct position to make it work. "acriveDrivers" is a direct branch of the root, so the way I placed it is as if it were a child of drivers, which seems wrong to me, but I can't find the solution. The rules at the beginning were like this (practically no security): { "rules": { ".read":true, ".write": true, "activeDrivers": { ".indexOn": ["g"] } } } New rules are: "rules": { "drivers": { "$uid": { ".read": "auth !== null && auth.uid === $uid", ".write": "auth !== null && auth.uid === $uid", "activeDrivers": { ".indexOn": ["g"] } } } } This is the JSON of the Database: { "ALL Ride Requests": { "-NJlIOrp49pNBSuuEawT": { "destination": { "latitude": "41.929612", "longitude": "12.4858561" }, "destinationAddress": "Duke's", "driverId": "waiting", "origin": { "latitude": "41.919225", "longitude": "12.5266267" }, "originAddress": "Circonvallazione Nomentana, 270, 00162 Roma RM, Italy", "time": "2022-12-20 21:50:48.437521", "userName": "Peter Parker", "userPhone": "090012321354" }, }, "activeDrivers": { "31uMBJKvl6PF7BVKQnqHORTrWRP2": { ".priority": "sr2yt23wk8", "g": "sr2yt23wl8", "l": [ 41.926275, 12.5376567 ] }, "G3OJ79KiLeMmxqoUpJ1NggIKbiF2": { ".priority": "sr2yt23wk8", "g": "sr2yt23rk8", "l": [ 41.926275, 12.5376567 ] }, "filTJu3xjiQYTzehD71kzY1Oybz1": { ".priority": "sr2yt23wk8", "g": "sr2yy23wk8", "l": [ 41.926275, 12.5376567 ] } }, "drivers": { "G3OJ79KiLeMmxqoUpJ1NggIKbiF2": { "earnings": "0.0", "email": "simo#hotmail.it", "id": "G3OJ79KiLeMmxqoUpJ1NggIKbiF2", "name": "Simone Demichele Test", "newRideStatus": "idle", "password": "testpassword", "phone": "3452362585", "token": "fFIwv1IHRv2ylXyW-qRVGQ:APA91bH7IfcNBBi7Y53wRjQKN12-nBUgFHHpf7F0LeWCstG_MIqt-mkobRN6nvUZxqbMnMlXU2yMHdE-efYykUdtcXl-91wW5rGyQcpMl6Dij6bxC8snQRkAMGBhQUmyqYW6sBhY6Ul3" }, "Gzs0qxNiE6VZrwNGPYpFPRB7J8p1": { "email": "giacomo#gmail.com", "id": "Gzs0qxNiE6VZrwNGPYpFPRB7J8p1", "name": "giacomo", "newRideStatus": "idle", "phone": "134634564352", "token": "cdG8W0lFRZ2F0jAeG2WbnO:APA91bHTtbtSg18sPNxcH92TIdM3UuX-qcim2-h0I_1YPcBgucIGO0I3ACIQEGVpmsg-EKcRZXFIMIXlxGk1iBw-V0hmDZBVWDyFh44yH2iM8fZgrhRsQzyVBdXdLxGMI0Vz67hQFUQU" }, "OLhsoowb9FXTBtWQmGysGLLBgNz2": { "email": "gino#gmail.com", "id": "OLhsoowb9FXTBtWQmGysGLLBgNz2", "name": "Gino", "phone": "4568965432", "token": "ewktnxHKRSCBWwilm_SDfd:APA91bFchfCs_33zZNGNtbUHPf6TBC3Vrua7U4QT0bX_e4cr6Z62XSPr5TwZyL-BQ12fmDa3XKnAqeLDQy7NMUKp9m8bq676jS_i5n1vjNMFYJ4tHfIYjntEwYKvOcsTp0yh4ZSvjuxb" }, "ZYqM7SbG3IhRBAGCfXRZHHs7XdG3": { "email": "laura#gmail.com", "id": "ZYqM7SbG3IhRBAGCfXRZHHs7XdG3", "name": "Laura", "newRideStatus": "idle", "phone": "1212432554325", "token": "cdG8W0lFRZ2F0jAeG2WbnO:APA91bHTtbtSg18sPNxcH92TIdM3UuX-qcim2-h0I_1YPcBgucIGO0I3ACIQEGVpmsg-EKcRZXFIMIXlxGk1iBw-V0hmDZBVWDyFh44yH2iM8fZgrhRsQzyVBdXdLxGMI0Vz67hQFUQU" }, "filTJu3xjiQYTzehD71kzY1Oybz1": { "email": "maria#gmail.com", "id": "filTJu3xjiQYTzehD71kzY1Oybz1", "name": "Maria", "newRideStatus": "idle", "phone": "3726761919", "token": "fFIwv1IHRv2ylXyW-qRVGQ:APA91bH7IfcNBBi7Y53wRjQKN12-nBUgFHHpf7F0LeWCstG_MIqt-mkobRN6nvUZxqbMnMlXU2yMHdE-efYykUdtcXl-91wW5rGyQcpMl6Dij6bxC8snQRkAMGBhQUmyqYW6sBhY6Ul3" } }, "users": { "yHc7xseCT0QePnpolGHZvdr8ARV2": { "email": "peter#gmail.com", "id": "yHc7xseCT0QePnpolGHZvdr8ARV2", "name": "Peter Parker", "phone": "090012321354" } } } This is the query Position pos = await Geolocator.getCurrentPosition( desiredAccuracy: LocationAccuracy.high, ); driverCurrentPosition = pos; Geofire.initialize("activeDrivers"); Geofire.setLocation( currentFirebaseUser!.uid, driverCurrentPosition!.latitude, driverCurrentPosition!.longitude );
swift 3 countries list with phone code?
i am new with swift , i am trying to get list of countries with Phone code example +1 or +92 , i am trying to print our with : let networkInfo = CTTelephonyNetworkInfo() let carrier = networkInfo.subscriberCellularProvider let phoneCode = carrier?.mobileNetworkCode print(phoneCode) let countryCode = NSLocale.isoCountryCodes for country in countryCode { print(country) } phoneCode output is 03 which is wrong it should be +961 and the result of country is ios name 2 , example ZA,YT etc how to get full country name ? should i use custom JSON !
Try This dictionary with [country:code] to get country name and country phone code. class CountryPhoneCodeAndName: NSObject { var countryWithCode = [CountryNameWithCode]() var countryDictionary = ["AF":"93", "AL":"355", "DZ":"213","AS":"1", "AD":"376", "AO":"244", "AI":"1","AG":"1","AR":"54","AM":"374","AW":"297","AU":"61","AT":"43","AZ":"994","BS":"1","BH":"973","BD":"880","BB":"1","BY":"375","BE":"32","BZ":"501","BJ":"229","BM":"1","BT":"975","BA":"387","BW":"267","BR":"55","IO":"246","BG":"359","BF":"226","BI":"257","KH":"855","CM":"237","CA":"1","CV":"238","KY":"345","CF":"236","TD":"235","CL":"56","CN":"86","CX":"61","CO":"57","KM":"269","CG":"242","CK":"682","CR":"506","HR":"385","CU":"53","CY":"537","CZ":"420","DK":"45","DJ":"253","DM":"1","DO":"1","EC":"593","EG":"20","SV":"503","GQ":"240","ER":"291","EE":"372","ET":"251","FO":"298","FJ":"679","FI":"358","FR":"33","GF":"594","PF":"689","GA":"241","GM":"220","GE":"995","DE":"49","GH":"233","GI":"350","GR":"30","GL":"299","GD":"1","GP":"590","GU":"1","GT":"502","GN":"224","GW":"245","GY":"595","HT":"509","HN":"504","HU":"36","IS":"354","IN":"91","ID":"62","IQ":"964","IE":"353","IL":"972","IT":"39","JM":"1","JP":"81","JO":"962","KZ":"77","KE":"254","KI":"686","KW":"965","KG":"996","LV":"371","LB":"961","LS":"266","LR":"231","LI":"423","LT":"370","LU":"352","MG":"261","MW":"265","MY":"60","MV":"960","ML":"223","MT":"356","MH":"692","MQ":"596","MR":"222","MU":"230","YT":"262","MX":"52","MC":"377","MN":"976","ME":"382","MS":"1","MA":"212","MM":"95","NA":"264","NR":"674","NP":"977","NL":"31","AN":"599","NC":"687","NZ":"64","NI":"505","NE":"227","NG":"234","NU":"683","NF":"672","MP":"1","NO":"47","OM":"968","PK":"92","PW":"680","PA":"507","PG":"675","PY":"595","PE":"51","PH":"63","PL":"48","PT":"351","PR":"1","QA":"974","RO":"40","RW":"250","WS":"685","SM":"378","SA":"966","SN":"221","RS":"381","SC":"248","SL":"232","SG":"65","SK":"421","SI":"386","SB":"677","ZA":"27","GS":"500","ES":"34","LK":"94","SD":"249","SR":"597","SZ":"268","SE":"46","CH":"41","TJ":"992","TH":"66","TG":"228","TK":"690","TO":"676","TT":"1","TN":"216","TR":"90","TM":"993","TC":"1","TV":"688","UG":"256","UA":"380","AE":"971","GB":"44","US":"1", "UY":"598","UZ":"998", "VU":"678", "WF":"681","YE":"967","ZM":"260","ZW":"263","BO":"591","BN":"673","CC":"61","CD":"243","CI":"225","FK":"500","GG":"44","VA":"379","HK":"852","IR":"98","IM":"44","JE":"44","KP":"850","KR":"82","LA":"856","LY":"218","MO":"853","MK":"389","FM":"691","MD":"373","MZ":"258","PS":"970","PN":"872","RE":"262","RU":"7","BL":"590","SH":"290","KN":"1","LC":"1","MF":"590","PM":"508","VC":"1","ST":"239","SO":"252","SJ":"47","SY":"963","TW":"886","TZ":"255","TL":"670","VE":"58","VN":"84","VG":"284","VI":"340"] func getCountryName() { // Sorting all keys let keys = countryDictionary.keys let keysValue = keys.sorted { (first, second) -> Bool in let key1: String = first let key2: String = second let result = key1.compare(key2) == .orderedAscending return result } print(keysValue) for key in keysValue{ let countryKeyValue = CountryNameWithCode() print(countryDictionary[key] ?? "not") countryKeyValue.countryCode = countryDictionary[key]! countryKeyValue.countryName = Locale.current.localizedString(forRegionCode: key)! print(Locale.current.localizedString(forRegionCode: key)!) countryWithCode.append(countryKeyValue) } } class CountryNameWithCode: NSObject { var countryName = "" var countryCode = "" } }
Here It is the list of country codes JSON [ { "name": "Afghanistan", "dial_code": "+93", "code": "AF" }, { "name": "Åland Islands", "dial_code": "+358", "code": "AX" }, { "name": "Albania", "dial_code": "+355", "code": "AL" }, { "name": "Algeria", "dial_code": "+213", "code": "DZ" }, { "name": "American Samoa", "dial_code": "+1684", "code": "AS" }, { "name": "Andorra", "dial_code": "+376", "code": "AD" }, { "name": "Angola", "dial_code": "+244", "code": "AO" }, { "name": "Anguilla", "dial_code": "+1264", "code": "AI" }, { "name": "Antarctica", "dial_code": "+672", "code": "AQ" }, { "name": "Antigua and Barbuda", "dial_code": "+1268", "code": "AG" }, { "name": "Argentina", "dial_code": "+54", "code": "AR" }, { "name": "Armenia", "dial_code": "+374", "code": "AM" }, { "name": "Aruba", "dial_code": "+297", "code": "AW" }, { "name": "Australia", "dial_code": "+61", "code": "AU" }, { "name": "Austria", "dial_code": "+43", "code": "AT" }, { "name": "Azerbaijan", "dial_code": "+994", "code": "AZ" }, { "name": "Bahamas", "dial_code": "+1242", "code": "BS" }, { "name": "Bahrain", "dial_code": "+973", "code": "BH" }, { "name": "Bangladesh", "dial_code": "+880", "code": "BD" }, { "name": "Barbados", "dial_code": "+1246", "code": "BB" }, { "name": "Belarus", "dial_code": "+375", "code": "BY" }, { "name": "Belgium", "dial_code": "+32", "code": "BE" }, { "name": "Belize", "dial_code": "+501", "code": "BZ" }, { "name": "Benin", "dial_code": "+229", "code": "BJ" }, { "name": "Bermuda", "dial_code": "+1441", "code": "BM" }, { "name": "Bhutan", "dial_code": "+975", "code": "BT" }, { "name": "Bolivia, Plurinational State of bolivia", "dial_code": "+591", "code": "BO" }, { "name": "Bosnia and Herzegovina", "dial_code": "+387", "code": "BA" }, { "name": "Botswana", "dial_code": "+267", "code": "BW" }, { "name": "Bouvet Island", "dial_code": "+47", "code": "BV" }, { "name": "Brazil", "dial_code": "+55", "code": "BR" }, { "name": "British Indian Ocean Territory", "dial_code": "+246", "code": "IO" }, { "name": "Brunei Darussalam", "dial_code": "+673", "code": "BN" }, { "name": "Bulgaria", "dial_code": "+359", "code": "BG" }, { "name": "Burkina Faso", "dial_code": "+226", "code": "BF" }, { "name": "Burundi", "dial_code": "+257", "code": "BI" }, { "name": "Cambodia", "dial_code": "+855", "code": "KH" }, { "name": "Cameroon", "dial_code": "+237", "code": "CM" }, { "name": "Canada", "dial_code": "+1", "code": "CA" }, { "name": "Cape Verde", "dial_code": "+238", "code": "CV" }, { "name": "Cayman Islands", "dial_code": "+ 345", "code": "KY" }, { "name": "Central African Republic", "dial_code": "+236", "code": "CF" }, { "name": "Chad", "dial_code": "+235", "code": "TD" }, { "name": "Chile", "dial_code": "+56", "code": "CL" }, { "name": "China", "dial_code": "+86", "code": "CN" }, { "name": "Christmas Island", "dial_code": "+61", "code": "CX" }, { "name": "Cocos (Keeling) Islands", "dial_code": "+61", "code": "CC" }, { "name": "Colombia", "dial_code": "+57", "code": "CO" }, { "name": "Comoros", "dial_code": "+269", "code": "KM" }, { "name": "Congo", "dial_code": "+242", "code": "CG" }, { "name": "Congo, The Democratic Republic of the Congo", "dial_code": "+243", "code": "CD" }, { "name": "Cook Islands", "dial_code": "+682", "code": "CK" }, { "name": "Costa Rica", "dial_code": "+506", "code": "CR" }, { "name": "Cote d'Ivoire", "dial_code": "+225", "code": "CI" }, { "name": "Croatia", "dial_code": "+385", "code": "HR" }, { "name": "Cuba", "dial_code": "+53", "code": "CU" }, { "name": "Cyprus", "dial_code": "+357", "code": "CY" }, { "name": "Czech Republic", "dial_code": "+420", "code": "CZ" }, { "name": "Denmark", "dial_code": "+45", "code": "DK" }, { "name": "Djibouti", "dial_code": "+253", "code": "DJ" }, { "name": "Dominica", "dial_code": "+1767", "code": "DM" }, { "name": "Dominican Republic", "dial_code": "+1849", "code": "DO" }, { "name": "Ecuador", "dial_code": "+593", "code": "EC" }, { "name": "Egypt", "dial_code": "+20", "code": "EG" }, { "name": "El Salvador", "dial_code": "+503", "code": "SV" }, { "name": "Equatorial Guinea", "dial_code": "+240", "code": "GQ" }, { "name": "Eritrea", "dial_code": "+291", "code": "ER" }, { "name": "Estonia", "dial_code": "+372", "code": "EE" }, { "name": "Ethiopia", "dial_code": "+251", "code": "ET" }, { "name": "Falkland Islands (Malvinas)", "dial_code": "+500", "code": "FK" }, { "name": "Faroe Islands", "dial_code": "+298", "code": "FO" }, { "name": "Fiji", "dial_code": "+679", "code": "FJ" }, { "name": "Finland", "dial_code": "+358", "code": "FI" }, { "name": "France", "dial_code": "+33", "code": "FR" }, { "name": "French Guiana", "dial_code": "+594", "code": "GF" }, { "name": "French Polynesia", "dial_code": "+689", "code": "PF" }, { "name": "French Southern Territories", "dial_code": "+262", "code": "TF" }, { "name": "Gabon", "dial_code": "+241", "code": "GA" }, { "name": "Gambia", "dial_code": "+220", "code": "GM" }, { "name": "Georgia", "dial_code": "+995", "code": "GE" }, { "name": "Germany", "dial_code": "+49", "code": "DE" }, { "name": "Ghana", "dial_code": "+233", "code": "GH" }, { "name": "Gibraltar", "dial_code": "+350", "code": "GI" }, { "name": "Greece", "dial_code": "+30", "code": "GR" }, { "name": "Greenland", "dial_code": "+299", "code": "GL" }, { "name": "Grenada", "dial_code": "+1473", "code": "GD" }, { "name": "Guadeloupe", "dial_code": "+590", "code": "GP" }, { "name": "Guam", "dial_code": "+1671", "code": "GU" }, { "name": "Guatemala", "dial_code": "+502", "code": "GT" }, { "name": "Guernsey", "dial_code": "+44", "code": "GG" }, { "name": "Guinea", "dial_code": "+224", "code": "GN" }, { "name": "Guinea-Bissau", "dial_code": "+245", "code": "GW" }, { "name": "Guyana", "dial_code": "+592", "code": "GY" }, { "name": "Haiti", "dial_code": "+509", "code": "HT" }, { "name": "Heard Island and Mcdonald Islands", "dial_code": "+0", "code": "HM" }, { "name": "Holy See (Vatican City State)", "dial_code": "+379", "code": "VA" }, { "name": "Honduras", "dial_code": "+504", "code": "HN" }, { "name": "Hong Kong", "dial_code": "+852", "code": "HK" }, { "name": "Hungary", "dial_code": "+36", "code": "HU" }, { "name": "Iceland", "dial_code": "+354", "code": "IS" }, { "name": "India", "dial_code": "+91", "code": "IN" }, { "name": "Indonesia", "dial_code": "+62", "code": "ID" }, { "name": "Iran, Islamic Republic of Persian Gulf", "dial_code": "+98", "code": "IR" }, { "name": "Iraq", "dial_code": "+964", "code": "IQ" }, { "name": "Ireland", "dial_code": "+353", "code": "IE" }, { "name": "Isle of Man", "dial_code": "+44", "code": "IM" }, { "name": "Israel", "dial_code": "+972", "code": "IL" }, { "name": "Italy", "dial_code": "+39", "code": "IT" }, { "name": "Jamaica", "dial_code": "+1876", "code": "JM" }, { "name": "Japan", "dial_code": "+81", "code": "JP" }, { "name": "Jersey", "dial_code": "+44", "code": "JE" }, { "name": "Jordan", "dial_code": "+962", "code": "JO" }, { "name": "Kazakhstan", "dial_code": "+7", "code": "KZ" }, { "name": "Kenya", "dial_code": "+254", "code": "KE" }, { "name": "Kiribati", "dial_code": "+686", "code": "KI" }, { "name": "Korea, Democratic People's Republic of Korea", "dial_code": "+850", "code": "KP" }, { "name": "Korea, Republic of South Korea", "dial_code": "+82", "code": "KR" }, { "name": "Kosovo", "dial_code": "+383", "code": "XK" }, { "name": "Kuwait", "dial_code": "+965", "code": "KW" }, { "name": "Kyrgyzstan", "dial_code": "+996", "code": "KG" }, { "name": "Laos", "dial_code": "+856", "code": "LA" }, { "name": "Latvia", "dial_code": "+371", "code": "LV" }, { "name": "Lebanon", "dial_code": "+961", "code": "LB" }, { "name": "Lesotho", "dial_code": "+266", "code": "LS" }, { "name": "Liberia", "dial_code": "+231", "code": "LR" }, { "name": "Libyan Arab Jamahiriya", "dial_code": "+218", "code": "LY" }, { "name": "Liechtenstein", "dial_code": "+423", "code": "LI" }, { "name": "Lithuania", "dial_code": "+370", "code": "LT" }, { "name": "Luxembourg", "dial_code": "+352", "code": "LU" }, { "name": "Macao", "dial_code": "+853", "code": "MO" }, { "name": "Macedonia", "dial_code": "+389", "code": "MK" }, { "name": "Madagascar", "dial_code": "+261", "code": "MG" }, { "name": "Malawi", "dial_code": "+265", "code": "MW" }, { "name": "Malaysia", "dial_code": "+60", "code": "MY" }, { "name": "Maldives", "dial_code": "+960", "code": "MV" }, { "name": "Mali", "dial_code": "+223", "code": "ML" }, { "name": "Malta", "dial_code": "+356", "code": "MT" }, { "name": "Marshall Islands", "dial_code": "+692", "code": "MH" }, { "name": "Martinique", "dial_code": "+596", "code": "MQ" }, { "name": "Mauritania", "dial_code": "+222", "code": "MR" }, { "name": "Mauritius", "dial_code": "+230", "code": "MU" }, { "name": "Mayotte", "dial_code": "+262", "code": "YT" }, { "name": "Mexico", "dial_code": "+52", "code": "MX" }, { "name": "Micronesia, Federated States of Micronesia", "dial_code": "+691", "code": "FM" }, { "name": "Moldova", "dial_code": "+373", "code": "MD" }, { "name": "Monaco", "dial_code": "+377", "code": "MC" }, { "name": "Mongolia", "dial_code": "+976", "code": "MN" }, { "name": "Montenegro", "dial_code": "+382", "code": "ME" }, { "name": "Montserrat", "dial_code": "+1664", "code": "MS" }, { "name": "Morocco", "dial_code": "+212", "code": "MA" }, { "name": "Mozambique", "dial_code": "+258", "code": "MZ" }, { "name": "Myanmar", "dial_code": "+95", "code": "MM" }, { "name": "Namibia", "dial_code": "+264", "code": "NA" }, { "name": "Nauru", "dial_code": "+674", "code": "NR" }, { "name": "Nepal", "dial_code": "+977", "code": "NP" }, { "name": "Netherlands", "dial_code": "+31", "code": "NL" }, { "name": "Netherlands Antilles", "dial_code": "+599", "code": "AN" }, { "name": "New Caledonia", "dial_code": "+687", "code": "NC" }, { "name": "New Zealand", "dial_code": "+64", "code": "NZ" }, { "name": "Nicaragua", "dial_code": "+505", "code": "NI" }, { "name": "Niger", "dial_code": "+227", "code": "NE" }, { "name": "Nigeria", "dial_code": "+234", "code": "NG" }, { "name": "Niue", "dial_code": "+683", "code": "NU" }, { "name": "Norfolk Island", "dial_code": "+672", "code": "NF" }, { "name": "Northern Mariana Islands", "dial_code": "+1670", "code": "MP" }, { "name": "Norway", "dial_code": "+47", "code": "NO" }, { "name": "Oman", "dial_code": "+968", "code": "OM" }, { "name": "Pakistan", "dial_code": "+92", "code": "PK" }, { "name": "Palau", "dial_code": "+680", "code": "PW" }, { "name": "Palestinian Territory, Occupied", "dial_code": "+970", "code": "PS" }, { "name": "Panama", "dial_code": "+507", "code": "PA" }, { "name": "Papua New Guinea", "dial_code": "+675", "code": "PG" }, { "name": "Paraguay", "dial_code": "+595", "code": "PY" }, { "name": "Peru", "dial_code": "+51", "code": "PE" }, { "name": "Philippines", "dial_code": "+63", "code": "PH" }, { "name": "Pitcairn", "dial_code": "+64", "code": "PN" }, { "name": "Poland", "dial_code": "+48", "code": "PL" }, { "name": "Portugal", "dial_code": "+351", "code": "PT" }, { "name": "Puerto Rico", "dial_code": "+1939", "code": "PR" }, { "name": "Qatar", "dial_code": "+974", "code": "QA" }, { "name": "Romania", "dial_code": "+40", "code": "RO" }, { "name": "Russia", "dial_code": "+7", "code": "RU" }, { "name": "Rwanda", "dial_code": "+250", "code": "RW" }, { "name": "Reunion", "dial_code": "+262", "code": "RE" }, { "name": "Saint Barthelemy", "dial_code": "+590", "code": "BL" }, { "name": "Saint Helena, Ascension and Tristan Da Cunha", "dial_code": "+290", "code": "SH" }, { "name": "Saint Kitts and Nevis", "dial_code": "+1869", "code": "KN" }, { "name": "Saint Lucia", "dial_code": "+1758", "code": "LC" }, { "name": "Saint Martin", "dial_code": "+590", "code": "MF" }, { "name": "Saint Pierre and Miquelon", "dial_code": "+508", "code": "PM" }, { "name": "Saint Vincent and the Grenadines", "dial_code": "+1784", "code": "VC" }, { "name": "Samoa", "dial_code": "+685", "code": "WS" }, { "name": "San Marino", "dial_code": "+378", "code": "SM" }, { "name": "Sao Tome and Principe", "dial_code": "+239", "code": "ST" }, { "name": "Saudi Arabia", "dial_code": "+966", "code": "SA" }, { "name": "Senegal", "dial_code": "+221", "code": "SN" }, { "name": "Serbia", "dial_code": "+381", "code": "RS" }, { "name": "Seychelles", "dial_code": "+248", "code": "SC" }, { "name": "Sierra Leone", "dial_code": "+232", "code": "SL" }, { "name": "Singapore", "dial_code": "+65", "code": "SG" }, { "name": "Slovakia", "dial_code": "+421", "code": "SK" }, { "name": "Slovenia", "dial_code": "+386", "code": "SI" }, { "name": "Solomon Islands", "dial_code": "+677", "code": "SB" }, { "name": "Somalia", "dial_code": "+252", "code": "SO" }, { "name": "South Africa", "dial_code": "+27", "code": "ZA" }, { "name": "South Sudan", "dial_code": "+211", "code": "SS" }, { "name": "South Georgia and the South Sandwich Islands", "dial_code": "+500", "code": "GS" }, { "name": "Spain", "dial_code": "+34", "code": "ES" }, { "name": "Sri Lanka", "dial_code": "+94", "code": "LK" }, { "name": "Sudan", "dial_code": "+249", "code": "SD" }, { "name": "Suriname", "dial_code": "+597", "code": "SR" }, { "name": "Svalbard and Jan Mayen", "dial_code": "+47", "code": "SJ" }, { "name": "Swaziland", "dial_code": "+268", "code": "SZ" }, { "name": "Sweden", "dial_code": "+46", "code": "SE" }, { "name": "Switzerland", "dial_code": "+41", "code": "CH" }, { "name": "Syrian Arab Republic", "dial_code": "+963", "code": "SY" }, { "name": "Taiwan", "dial_code": "+886", "code": "TW" }, { "name": "Tajikistan", "dial_code": "+992", "code": "TJ" }, { "name": "Tanzania, United Republic of Tanzania", "dial_code": "+255", "code": "TZ" }, { "name": "Thailand", "dial_code": "+66", "code": "TH" }, { "name": "Timor-Leste", "dial_code": "+670", "code": "TL" }, { "name": "Togo", "dial_code": "+228", "code": "TG" }, { "name": "Tokelau", "dial_code": "+690", "code": "TK" }, { "name": "Tonga", "dial_code": "+676", "code": "TO" }, { "name": "Trinidad and Tobago", "dial_code": "+1868", "code": "TT" }, { "name": "Tunisia", "dial_code": "+216", "code": "TN" }, { "name": "Turkey", "dial_code": "+90", "code": "TR" }, { "name": "Turkmenistan", "dial_code": "+993", "code": "TM" }, { "name": "Turks and Caicos Islands", "dial_code": "+1649", "code": "TC" }, { "name": "Tuvalu", "dial_code": "+688", "code": "TV" }, { "name": "Uganda", "dial_code": "+256", "code": "UG" }, { "name": "Ukraine", "dial_code": "+380", "code": "UA" }, { "name": "United Arab Emirates", "dial_code": "+971", "code": "AE" }, { "name": "United Kingdom", "dial_code": "+44", "code": "GB" }, { "name": "United States", "dial_code": "+1", "code": "US" }, { "name": "Uruguay", "dial_code": "+598", "code": "UY" }, { "name": "Uzbekistan", "dial_code": "+998", "code": "UZ" }, { "name": "Vanuatu", "dial_code": "+678", "code": "VU" }, { "name": "Venezuela, Bolivarian Republic of Venezuela", "dial_code": "+58", "code": "VE" }, { "name": "Vietnam", "dial_code": "+84", "code": "VN" }, { "name": "Virgin Islands, British", "dial_code": "+1284", "code": "VG" }, { "name": "Virgin Islands, U.S.", "dial_code": "+1340", "code": "VI" }, { "name": "Wallis and Futuna", "dial_code": "+681", "code": "WF" }, { "name": "Yemen", "dial_code": "+967", "code": "YE" }, { "name": "Zambia", "dial_code": "+260", "code": "ZM" }, { "name": "Zimbabwe", "dial_code": "+263", "code": "ZW" } ]
You can get full country name with: let networkInformation = CTTelephonyNetworkInfo() if let carrier = networkInformation.subscriberCellularProvider { print("phone code:" + carrier.mobileNetworkCode!) print("ISO country code: " + carrier.isoCountryCode!) // Convert ISO country code to full country name let currentLocale = NSLocale.init(localeIdentifier: NSLocale.current.identifier) let fullCountryName = currentLocale.displayName(forKey: NSLocale.Key.countryCode, value: carrier.isoCountryCode!) print(fullCountryName) } And for country prefix number I think the best way is to use custom dictionary with [country:code] values.
I did it in this simple way: struct CountryCodeCategory { let id: Int let name: String let countries: [CountryCode] } struct CountryCode { let id: Int let code: String let name: String let categoryId: Int } class CountryCodeList{ let categories = [ CountryCodeCategory(id: 0, name: "A", countries: [ CountryCode(id: 0, code: "+7 840", name: "Abkhazia", categoryId: 0), CountryCode(id: 1, code: "+93", name: "Afghanistan", categoryId: 0), CountryCode(id: 2, code: "+355", name: "Albania", categoryId: 0), CountryCode(id: 3, code: "+213", name: "Algeria", categoryId: 0), CountryCode(id: 4, code: "+1 684", name: "American Samoa", categoryId: 0), CountryCode(id: 5, code: "+376", name: "Andorra", categoryId: 0), CountryCode(id: 6, code: "+244", name: "Angola", categoryId: 0), CountryCode(id: 7, code: "+1 264", name: "Anguilla", categoryId: 0), CountryCode(id: 8, code: "+1 268", name: "Antigua and Barbuda", categoryId: 0), CountryCode(id: 9, code: "+54", name: "Argentina", categoryId: 0), CountryCode(id: 10, code: "+374", name: "Armenia", categoryId: 0), CountryCode(id: 11, code: "+297", name: "Aruba", categoryId: 0), CountryCode(id: 12, code: "+247", name: "Ascension", categoryId: 0), CountryCode(id: 13, code: "+61", name: "Australia", categoryId: 0), CountryCode(id: 14, code: "+672", name: "Australian External Territories", categoryId: 0), CountryCode(id: 15, code: "+43", name: "Austria", categoryId: 0), CountryCode(id: 16, code: "+994", name: "Azerbaijan", categoryId: 0), ]), CountryCodeCategory(id: 1, name: "B", countries: [ CountryCode(id: 17, code: "+1 242", name: "Bahamas", categoryId: 1), CountryCode(id: 18, code: "+973", name: "Bahrain", categoryId: 1), CountryCode(id: 19, code: "+880", name: "Bangladesh", categoryId: 1), CountryCode(id: 20, code: "+1 246", name: "Barbados", categoryId: 1), CountryCode(id: 21, code: "+1 268", name: "Barbuda", categoryId: 1), CountryCode(id: 22, code: "+375", name: "Belarus", categoryId: 1), CountryCode(id: 23, code: "+32", name: "Belgium", categoryId: 1), CountryCode(id: 24, code: "+501", name: "Belize", categoryId: 1), CountryCode(id: 25, code: "+229", name: "Benin", categoryId: 1), CountryCode(id: 26, code: "+1 441", name: "Bermuda", categoryId: 1), CountryCode(id: 27, code: "+975", name: "Bhutan", categoryId: 1), CountryCode(id: 28, code: "+591", name: "Bolivia", categoryId: 1), CountryCode(id: 29, code: "+387", name: "Bosnia and Herzegovina", categoryId: 1), CountryCode(id: 30, code: "+267", name: "Botswana", categoryId: 1), CountryCode(id: 31, code: "+55", name: "Brazil", categoryId: 1), CountryCode(id: 32, code: "+246", name: "British Indian Ocean Territory", categoryId: 1), CountryCode(id: 33, code: "+1 284", name: "British Virgin Islands", categoryId: 1), CountryCode(id: 34, code: "+673", name: "Brunei", categoryId: 1), CountryCode(id: 35, code: "+359", name: "Bulgaria", categoryId: 1), CountryCode(id: 36, code: "+226", name: "Burkina Faso", categoryId: 1), CountryCode(id: 37, code: "+257", name: "Burundi", categoryId: 1), ]), CountryCodeCategory(id: 2, name: "C", countries: [ CountryCode(id: 38, code: "+855", name: "Cambodia", categoryId: 2), CountryCode(id: 39, code: "+237", name: "Cameroon", categoryId: 2), CountryCode(id: 40, code: "+1", name: "Canada", categoryId: 2), CountryCode(id: 41, code: "+238", name: "Cape Verde", categoryId: 2), CountryCode(id: 42, code: "+ 345", name: "Cayman Islands", categoryId: 2), CountryCode(id: 43, code: "+236", name: "Central African Republic", categoryId: 2), CountryCode(id: 44, code: "+235", name: "Chad", categoryId: 2), CountryCode(id: 45, code: "+56", name: "Chile", categoryId: 2), CountryCode(id: 46, code: "+86", name: "China", categoryId: 2), CountryCode(id: 47, code: "+61", name: "Christmas Island", categoryId: 2), CountryCode(id: 48, code: "+61", name: "Cocos-Keeling Islands", categoryId: 2), CountryCode(id: 49, code: "+57", name: "Colombia", categoryId: 2), CountryCode(id: 50, code: "+269", name: "Comoros", categoryId: 2), CountryCode(id: 51, code: "+242", name: "Congo", categoryId: 2), CountryCode(id: 52, code: "+243", name: "Congo, Dem. Rep. of (Zaire)", categoryId: 2), CountryCode(id: 53, code: "+682", name: "Cook Islands", categoryId: 2), CountryCode(id: 54, code: "+506", name: "Costa Rica", categoryId: 2), CountryCode(id: 55, code: "+385", name: "Croatia", categoryId: 2), CountryCode(id: 56, code: "+53", name: "Cuba", categoryId: 2), CountryCode(id: 57, code: "+599", name: "Curacao", categoryId: 2), CountryCode(id: 58, code: "+537", name: "Cyprus", categoryId: 2), CountryCode(id: 59, code: "+420", name: "Czech Republic", categoryId: 2), ]), CountryCodeCategory(id: 3, name: "D", countries: [ CountryCode(id: 60, code: "+45", name: "Denmark", categoryId: 3), CountryCode(id: 61, code: "+246", name: "Diego Garcia", categoryId: 3), CountryCode(id: 62, code: "+253", name: "Djibouti", categoryId: 3), CountryCode(id: 63, code: "+1 767", name: "Dominica", categoryId: 3), CountryCode(id: 64, code: "+1 809", name: "Dominican Republic", categoryId: 3), ]), CountryCodeCategory(id: 4, name: "E", countries: [ CountryCode(id: 65, code: "+670", name: "East Timor", categoryId: 4), CountryCode(id: 66, code: "+56", name: "Easter Island", categoryId: 4), CountryCode(id: 67, code: "+593", name: "Ecuador", categoryId: 4), CountryCode(id: 68, code: "+20", name: "Egypt", categoryId: 4), CountryCode(id: 69, code: "+503", name: "El Salvador", categoryId: 4), CountryCode(id: 70, code: "+240", name: "Equatorial Guinea", categoryId: 4), CountryCode(id: 71, code: "+291", name: "Eritrea", categoryId: 4), CountryCode(id: 72, code: "+372", name: "Estonia", categoryId: 4), CountryCode(id: 73, code: "+251", name: "Ethiopia", categoryId: 4), ]), CountryCodeCategory(id: 5, name: "F", countries: [ CountryCode(id: 74, code: "+500", name: "Falkland Islands", categoryId: 5), CountryCode(id: 75, code: "+298", name: "Faroe Islands", categoryId: 5), CountryCode(id: 76, code: "+679", name: "Fiji", categoryId: 5), CountryCode(id: 77, code: "+358", name: "Finland", categoryId: 5), CountryCode(id: 78, code: "+33", name: "France", categoryId: 5), CountryCode(id: 79, code: "+596", name: "French Antilles", categoryId: 5), CountryCode(id: 80, code: "+594", name: "French Guiana", categoryId: 5), CountryCode(id: 81, code: "+689", name: "French Polynesia", categoryId: 5), ]), CountryCodeCategory(id: 6, name: "G", countries: [ CountryCode(id: 82, code: "+241", name: "Gabon", categoryId: 6), CountryCode(id: 83, code: "+220", name: "Gambia", categoryId: 6), CountryCode(id: 84, code: "+995", name: "Georgia", categoryId: 6), CountryCode(id: 85, code: "+49", name: "Germany", categoryId: 6), CountryCode(id: 86, code: "+233", name: "Ghana", categoryId: 6), CountryCode(id: 87, code: "+350", name: "Gibraltar", categoryId: 6), CountryCode(id: 88, code: "+30", name: "Greece", categoryId: 6), CountryCode(id: 89, code: "+299", name: "Greenland", categoryId: 6), CountryCode(id: 90, code: "+1 473", name: "Grenada", categoryId: 6), CountryCode(id: 91, code: "+590", name: "Guadeloupe", categoryId: 6), CountryCode(id: 92, code: "+1 671", name: "Guam", categoryId: 6), CountryCode(id: 93, code: "+502", name: "Guatemala", categoryId: 6), CountryCode(id: 94, code: "+224", name: "Guinea", categoryId: 6), CountryCode(id: 95, code: "+245", name: "Guinea-Bissau", categoryId: 6), CountryCode(id: 96, code: "+595", name: "Guyana", categoryId: 6), ]), CountryCodeCategory(id: 7, name: "H", countries: [ CountryCode(id: 97, code: "+509", name: "Haiti", categoryId: 7), CountryCode(id: 98, code: "+504", name: "Honduras", categoryId: 7), CountryCode(id: 99, code: "+852", name: "Hong Kong SAR China", categoryId: 7), CountryCode(id: 100, code: "+36", name: "Hungary", categoryId: 7), ]), CountryCodeCategory(id: 8, name: "I", countries: [ CountryCode(id: 101, code: "+354", name: "Iceland", categoryId: 8), CountryCode(id: 102, code: "+91", name: "India", categoryId: 8), CountryCode(id: 103, code: "+62", name: "Indonesia", categoryId: 8), CountryCode(id: 104, code: "+98", name: "Iran", categoryId: 8), CountryCode(id: 105, code: "+964", name: "Iraq", categoryId: 8), CountryCode(id: 106, code: "+353", name: "Ireland", categoryId: 8), CountryCode(id: 107, code: "+972", name: "Israel", categoryId: 8), CountryCode(id: 108, code: "+39", name: "Italy", categoryId: 8), CountryCode(id: 109, code: "+225", name: "Ivory Coast", categoryId: 8), ]), CountryCodeCategory(id: 9, name: "J", countries: [ CountryCode(id: 110, code: "+1 876", name: "Jamaica", categoryId: 9), CountryCode(id: 111, code: "+81", name: "Japan", categoryId: 9), CountryCode(id: 112, code: "+962", name: "Jordan", categoryId: 9), ]), CountryCodeCategory(id: 10, name: "K", countries: [ CountryCode(id: 113, code: "+7 7", name: "Kazakhstan", categoryId: 10), CountryCode(id: 114, code: "+254", name: "Kenya", categoryId: 10), CountryCode(id: 115, code: "+686", name: "Kiribati", categoryId: 10), CountryCode(id: 116, code: "+965", name: "Kuwait", categoryId: 10), CountryCode(id: 117, code: "+996", name: "Kyrgyzstan", categoryId: 10), ]), CountryCodeCategory(id: 11, name: "L", countries: [ CountryCode(id: 118, code: "+856", name: "Laos", categoryId: 11), CountryCode(id: 119, code: "+371", name: "Latvia", categoryId: 11), CountryCode(id: 120, code: "+961", name: "Lebanon", categoryId: 11), CountryCode(id: 121, code: "+266", name: "Lesotho", categoryId: 11), CountryCode(id: 122, code: "+231", name: "Liberia", categoryId: 11), CountryCode(id: 123, code: "+218", name: "Libya", categoryId: 11), CountryCode(id: 124, code: "+423", name: "Liechtenstein", categoryId: 11), CountryCode(id: 125, code: "+370", name: "Lithuania", categoryId: 11), CountryCode(id: 126, code: "+352", name: "Luxembourg", categoryId: 11), ]), CountryCodeCategory(id: 12, name: "M", countries: [ CountryCode(id: 127, code: "+853", name: "Macau SAR China", categoryId: 12), CountryCode(id: 128, code: "+389", name: "Macedonia", categoryId: 12), CountryCode(id: 129, code: "+261", name: "Madagascar", categoryId: 12), CountryCode(id: 130, code: "+265", name: "Malawi", categoryId: 12), CountryCode(id: 131, code: "+60", name: "Malaysia", categoryId: 12), CountryCode(id: 132, code: "+960", name: "Maldives", categoryId: 12), CountryCode(id: 133, code: "+223", name: "Mali", categoryId: 12), CountryCode(id: 134, code: "+356", name: "Malta", categoryId: 12), CountryCode(id: 135, code: "+692", name: "Marshall Islands", categoryId: 12), CountryCode(id: 136, code: "+596", name: "Martinique", categoryId: 12), CountryCode(id: 137, code: "+222", name: "Mauritania", categoryId: 12), CountryCode(id: 138, code: "+230", name: "Mauritius", categoryId: 12), CountryCode(id: 139, code: "+262", name: "Mayotte", categoryId: 12), CountryCode(id: 140, code: "+52", name: "Mexico", categoryId: 12), CountryCode(id: 141, code: "+691", name: "Micronesia", categoryId: 12), CountryCode(id: 142, code: "+1 808", name: "Midway Island", categoryId: 12), CountryCode(id: 143, code: "+373", name: "Moldova", categoryId: 12), CountryCode(id: 144, code: "+377", name: "Monaco", categoryId: 12), CountryCode(id: 145, code: "+976", name: "Mongolia", categoryId: 12), CountryCode(id: 146, code: "+382", name: "Montenegro", categoryId: 12), CountryCode(id: 147, code: "+1664", name: "Montserrat", categoryId: 12), CountryCode(id: 148, code: "+212", name: "Morocco", categoryId: 12), CountryCode(id: 149, code: "+95", name: "Myanmar", categoryId: 12), ]), CountryCodeCategory(id: 13, name: "N", countries: [ CountryCode(id: 150, code: "+264", name: "Namibia", categoryId: 13), CountryCode(id: 151, code: "+674", name: "Nauru", categoryId: 13), CountryCode(id: 152, code: "+977", name: "Nepal", categoryId: 13), CountryCode(id: 153, code: "+31", name: "Netherlands", categoryId: 13), CountryCode(id: 154, code: "+599", name: "Netherlands Antilles", categoryId: 13), CountryCode(id: 155, code: "+1 869", name: "Nevis", categoryId: 13), CountryCode(id: 156, code: "+687", name: "New Caledonia", categoryId: 13), CountryCode(id: 157, code: "+64", name: "New Zealand", categoryId: 13), CountryCode(id: 158, code: "+505", name: "Nicaragua", categoryId: 13), CountryCode(id: 159, code: "+227", name: "Niger", categoryId: 13), CountryCode(id: 160, code: "+234", name: "Nigeria", categoryId: 13), CountryCode(id: 161, code: "+683", name: "Niue", categoryId: 13), CountryCode(id: 162, code: "+672", name: "Norfolk Island", categoryId: 13), CountryCode(id: 163, code: "+850", name: "North Korea", categoryId: 13), CountryCode(id: 164, code: "+1 670", name: "Northern Mariana Islands", categoryId: 13), CountryCode(id: 165, code: "+47", name: "Norway", categoryId: 13), ]), CountryCodeCategory(id: 14, name: "O", countries: [ CountryCode(id: 166, code: "+968", name: "Oman", categoryId: 14), ]), CountryCodeCategory(id: 15, name: "P", countries: [ CountryCode(id: 167, code: "+92", name: "Pakistan", categoryId: 15), CountryCode(id: 168, code: "+680", name: "Palau", categoryId: 15), CountryCode(id: 169, code: "+970", name: "Palestinian Territory", categoryId: 15), CountryCode(id: 170, code: "+507", name: "Panama", categoryId: 15), CountryCode(id: 171, code: "+675", name: "Papua New Guinea", categoryId: 15), CountryCode(id: 172, code: "+595", name: "Paraguay", categoryId: 15), CountryCode(id: 173, code: "+51", name: "Peru", categoryId: 15), CountryCode(id: 174, code: "+63", name: "Philippines", categoryId: 15), CountryCode(id: 175, code: "+48", name: "Poland", categoryId: 15), CountryCode(id: 176, code: "+351", name: "Portugal", categoryId: 15), CountryCode(id: 177, code: "+1 787", name: "Puerto Rico", categoryId: 15), ]), CountryCodeCategory(id: 16, name: "Q", countries: [ CountryCode(id: 178, code: "+974", name: "Qatar", categoryId: 16), ]), CountryCodeCategory(id: 17, name: "R", countries: [ CountryCode(id: 179, code: "+262", name: "Reunion", categoryId: 17), CountryCode(id: 180, code: "+40", name: "Romania", categoryId: 17), CountryCode(id: 181, code: "+7", name: "Russia", categoryId: 17), CountryCode(id: 182, code: "+250", name: "Rwanda", categoryId: 17), ]), CountryCodeCategory(id: 18, name: "S", countries: [ CountryCode(id: 183, code: "+685", name: "Samoa", categoryId: 18), CountryCode(id: 184, code: "+378", name: "San Marino", categoryId: 18), CountryCode(id: 185, code: "+966", name: "Saudi Arabia", categoryId: 18), CountryCode(id: 186, code: "+221", name: "Senegal", categoryId: 18), CountryCode(id: 187, code: "+381", name: "Serbia", categoryId: 18), CountryCode(id: 188, code: "+248", name: "Seychelles", categoryId: 18), CountryCode(id: 189, code: "+232", name: "Sierra Leone", categoryId: 18), CountryCode(id: 190, code: "+65", name: "Singapore", categoryId: 18), CountryCode(id: 191, code: "+421", name: "Slovakia", categoryId: 18), CountryCode(id: 192, code: "+386", name: "Slovenia", categoryId: 18), CountryCode(id: 193, code: "+677", name: "Solomon Islands", categoryId: 18), CountryCode(id: 194, code: "+27", name: "South Africa", categoryId: 18), CountryCode(id: 195, code: "+500", name: "South Georgia and the South Sandwich Islands", categoryId: 18), CountryCode(id: 196, code: "+82", name: "South Korea", categoryId: 18), CountryCode(id: 197, code: "+34", name: "Spain", categoryId: 18), CountryCode(id: 198, code: "+94", name: "Sri Lanka", categoryId: 18), CountryCode(id: 199, code: "+249", name: "Sudan", categoryId: 18), CountryCode(id: 200, code: "+597", name: "Suriname", categoryId: 18), CountryCode(id: 201, code: "+268", name: "Swaziland", categoryId: 18), CountryCode(id: 202, code: "+46", name: "Sweden", categoryId: 18), CountryCode(id: 203, code: "+41", name: "Switzerland", categoryId: 18), CountryCode(id: 204, code: "+963", name: "Syria", categoryId: 18), ]), CountryCodeCategory(id: 19, name: "T", countries: [ CountryCode(id: 205, code: "+886", name: "Taiwan", categoryId: 19), CountryCode(id: 206, code: "+992", name: "Tajikistan", categoryId: 19), CountryCode(id: 207, code: "+255", name: "Tanzania", categoryId: 19), CountryCode(id: 208, code: "+66", name: "Thailand", categoryId: 19), CountryCode(id: 209, code: "+670", name: "Timor Leste", categoryId: 19), CountryCode(id: 210, code: "+228", name: "Togo", categoryId: 19), CountryCode(id: 211, code: "+690", name: "Tokelau", categoryId: 19), CountryCode(id: 212, code: "+676", name: "Tonga", categoryId: 19), CountryCode(id: 213, code: "+1 868", name: "Trinidad and Tobago", categoryId: 19), CountryCode(id: 214, code: "+216", name: "Tunisia", categoryId: 19), CountryCode(id: 215, code: "+90", name: "Turkey", categoryId: 19), CountryCode(id: 216, code: "+993", name: "Turkmenistan", categoryId: 19), CountryCode(id: 217, code: "+1 649", name: "Turks and Caicos Islands", categoryId: 19), CountryCode(id: 218, code: "+688", name: "Tuvalu", categoryId: 19), ]), CountryCodeCategory(id: 20, name: "U", countries: [ CountryCode(id: 219, code: "+1 340", name: "U.S. Virgin Islands", categoryId: 20), CountryCode(id: 220, code: "+256", name: "Uganda", categoryId: 20), CountryCode(id: 221, code: "+380", name: "Ukraine", categoryId: 20), CountryCode(id: 222, code: "+971", name: "United Arab Emirates", categoryId: 20), CountryCode(id: 223, code: "+44", name: "United Kingdom", categoryId: 20), CountryCode(id: 224, code: "+1", name: "United States", categoryId: 20), CountryCode(id: 225, code: "+598", name: "Uruguay", categoryId: 20), CountryCode(id: 226, code: "+998", name: "Uzbekistan", categoryId: 20), ]), CountryCodeCategory(id: 21, name: "V", countries: [ CountryCode(id: 227, code: "+678", name: "Vanuatu", categoryId: 21), CountryCode(id: 228, code: "+58", name: "Venezuela", categoryId: 21), CountryCode(id: 229, code: "+84", name: "Vietnam", categoryId: 21), ]), CountryCodeCategory(id: 22, name: "W", countries: [ CountryCode(id: 230, code: "+1 808", name: "Wake Island", categoryId: 22), CountryCode(id: 231, code: "+681", name: "Wallis and Futuna", categoryId: 22), ]), CountryCodeCategory(id: 23, name: "Y", countries: [ CountryCode(id: 232, code: "+967", name: "Yemen", categoryId: 23) ]), CountryCodeCategory(id: 24, name: "Z", countries: [ CountryCode(id: 233, code: "+260", name: "Zambia", categoryId: 24), CountryCode(id: 234, code: "+255", name: "Zanzibar", categoryId: 24), CountryCode(id: 235, code: "+263", name: "Zimbabwe", categoryId: 24) ]), ]
Thanks to #Sai kumar Reddy, here's a piece of python (<= 3.6) code which generates a swift struct and writes to file with country-name, dial-code and code. file = open("CountryCodes.swift", "x") file.write("import Foundation\n\n") file.write("struct CountryCode {\n") file.write("\tvar name: String\n") file.write("\tvar dialCode: String\n") file.write("\tvar code: String\n") file.write("}\n\n") file.write("var countryCodes: [CountryCode] = [\n") codes = [ { "name": "Afghanistan", "dial_code": "+93", "code": "AF" }, { "name": "Åland Islands", "dial_code": "+358", "code": "AX" }, { "name": "Albania", "dial_code": "+355", "code": "AL" }, { "name": "Algeria", "dial_code": "+213", "code": "DZ" }, { "name": "American Samoa", "dial_code": "+1684", "code": "AS" }, { "name": "Andorra", "dial_code": "+376", "code": "AD" }, { "name": "Angola", "dial_code": "+244", "code": "AO" }, { "name": "Anguilla", "dial_code": "+1264", "code": "AI" }, { "name": "Antarctica", "dial_code": "+672", "code": "AQ" }, { "name": "Antigua and Barbuda", "dial_code": "+1268", "code": "AG" }, { "name": "Argentina", "dial_code": "+54", "code": "AR" }, { "name": "Armenia", "dial_code": "+374", "code": "AM" }, { "name": "Aruba", "dial_code": "+297", "code": "AW" }, { "name": "Australia", "dial_code": "+61", "code": "AU" }, { "name": "Austria", "dial_code": "+43", "code": "AT" }, { "name": "Azerbaijan", "dial_code": "+994", "code": "AZ" }, { "name": "Bahamas", "dial_code": "+1242", "code": "BS" }, { "name": "Bahrain", "dial_code": "+973", "code": "BH" }, { "name": "Bangladesh", "dial_code": "+880", "code": "BD" }, { "name": "Barbados", "dial_code": "+1246", "code": "BB" }, { "name": "Belarus", "dial_code": "+375", "code": "BY" }, { "name": "Belgium", "dial_code": "+32", "code": "BE" }, { "name": "Belize", "dial_code": "+501", "code": "BZ" }, { "name": "Benin", "dial_code": "+229", "code": "BJ" }, { "name": "Bermuda", "dial_code": "+1441", "code": "BM" }, { "name": "Bhutan", "dial_code": "+975", "code": "BT" }, { "name": "Bolivia, Plurinational State of bolivia", "dial_code": "+591", "code": "BO" }, { "name": "Bosnia and Herzegovina", "dial_code": "+387", "code": "BA" }, { "name": "Botswana", "dial_code": "+267", "code": "BW" }, { "name": "Bouvet Island", "dial_code": "+47", "code": "BV" }, { "name": "Brazil", "dial_code": "+55", "code": "BR" }, { "name": "British Indian Ocean Territory", "dial_code": "+246", "code": "IO" }, { "name": "Brunei Darussalam", "dial_code": "+673", "code": "BN" }, { "name": "Bulgaria", "dial_code": "+359", "code": "BG" }, { "name": "Burkina Faso", "dial_code": "+226", "code": "BF" }, { "name": "Burundi", "dial_code": "+257", "code": "BI" }, { "name": "Cambodia", "dial_code": "+855", "code": "KH" }, { "name": "Cameroon", "dial_code": "+237", "code": "CM" }, { "name": "Canada", "dial_code": "+1", "code": "CA" }, { "name": "Cape Verde", "dial_code": "+238", "code": "CV" }, { "name": "Cayman Islands", "dial_code": "+ 345", "code": "KY" }, { "name": "Central African Republic", "dial_code": "+236", "code": "CF" }, { "name": "Chad", "dial_code": "+235", "code": "TD" }, { "name": "Chile", "dial_code": "+56", "code": "CL" }, { "name": "China", "dial_code": "+86", "code": "CN" }, { "name": "Christmas Island", "dial_code": "+61", "code": "CX" }, { "name": "Cocos (Keeling) Islands", "dial_code": "+61", "code": "CC" }, { "name": "Colombia", "dial_code": "+57", "code": "CO" }, { "name": "Comoros", "dial_code": "+269", "code": "KM" }, { "name": "Congo", "dial_code": "+242", "code": "CG" }, { "name": "Congo, The Democratic Republic of the Congo", "dial_code": "+243", "code": "CD" }, { "name": "Cook Islands", "dial_code": "+682", "code": "CK" }, { "name": "Costa Rica", "dial_code": "+506", "code": "CR" }, { "name": "Cote d'Ivoire", "dial_code": "+225", "code": "CI" }, { "name": "Croatia", "dial_code": "+385", "code": "HR" }, { "name": "Cuba", "dial_code": "+53", "code": "CU" }, { "name": "Cyprus", "dial_code": "+357", "code": "CY" }, { "name": "Czech Republic", "dial_code": "+420", "code": "CZ" }, { "name": "Denmark", "dial_code": "+45", "code": "DK" }, { "name": "Djibouti", "dial_code": "+253", "code": "DJ" }, { "name": "Dominica", "dial_code": "+1767", "code": "DM" }, { "name": "Dominican Republic", "dial_code": "+1849", "code": "DO" }, { "name": "Ecuador", "dial_code": "+593", "code": "EC" }, { "name": "Egypt", "dial_code": "+20", "code": "EG" }, { "name": "El Salvador", "dial_code": "+503", "code": "SV" }, { "name": "Equatorial Guinea", "dial_code": "+240", "code": "GQ" }, { "name": "Eritrea", "dial_code": "+291", "code": "ER" }, { "name": "Estonia", "dial_code": "+372", "code": "EE" }, { "name": "Ethiopia", "dial_code": "+251", "code": "ET" }, { "name": "Falkland Islands (Malvinas)", "dial_code": "+500", "code": "FK" }, { "name": "Faroe Islands", "dial_code": "+298", "code": "FO" }, { "name": "Fiji", "dial_code": "+679", "code": "FJ" }, { "name": "Finland", "dial_code": "+358", "code": "FI" }, { "name": "France", "dial_code": "+33", "code": "FR" }, { "name": "French Guiana", "dial_code": "+594", "code": "GF" }, { "name": "French Polynesia", "dial_code": "+689", "code": "PF" }, { "name": "French Southern Territories", "dial_code": "+262", "code": "TF" }, { "name": "Gabon", "dial_code": "+241", "code": "GA" }, { "name": "Gambia", "dial_code": "+220", "code": "GM" }, { "name": "Georgia", "dial_code": "+995", "code": "GE" }, { "name": "Germany", "dial_code": "+49", "code": "DE" }, { "name": "Ghana", "dial_code": "+233", "code": "GH" }, { "name": "Gibraltar", "dial_code": "+350", "code": "GI" }, { "name": "Greece", "dial_code": "+30", "code": "GR" }, { "name": "Greenland", "dial_code": "+299", "code": "GL" }, { "name": "Grenada", "dial_code": "+1473", "code": "GD" }, { "name": "Guadeloupe", "dial_code": "+590", "code": "GP" }, { "name": "Guam", "dial_code": "+1671", "code": "GU" }, { "name": "Guatemala", "dial_code": "+502", "code": "GT" }, { "name": "Guernsey", "dial_code": "+44", "code": "GG" }, { "name": "Guinea", "dial_code": "+224", "code": "GN" }, { "name": "Guinea-Bissau", "dial_code": "+245", "code": "GW" }, { "name": "Guyana", "dial_code": "+592", "code": "GY" }, { "name": "Haiti", "dial_code": "+509", "code": "HT" }, { "name": "Heard Island and Mcdonald Islands", "dial_code": "+0", "code": "HM" }, { "name": "Holy See (Vatican City State)", "dial_code": "+379", "code": "VA" }, { "name": "Honduras", "dial_code": "+504", "code": "HN" }, { "name": "Hong Kong", "dial_code": "+852", "code": "HK" }, { "name": "Hungary", "dial_code": "+36", "code": "HU" }, { "name": "Iceland", "dial_code": "+354", "code": "IS" }, { "name": "India", "dial_code": "+91", "code": "IN" }, { "name": "Indonesia", "dial_code": "+62", "code": "ID" }, { "name": "Iran, Islamic Republic of Persian Gulf", "dial_code": "+98", "code": "IR" }, { "name": "Iraq", "dial_code": "+964", "code": "IQ" }, { "name": "Ireland", "dial_code": "+353", "code": "IE" }, { "name": "Isle of Man", "dial_code": "+44", "code": "IM" }, { "name": "Israel", "dial_code": "+972", "code": "IL" }, { "name": "Italy", "dial_code": "+39", "code": "IT" }, { "name": "Jamaica", "dial_code": "+1876", "code": "JM" }, { "name": "Japan", "dial_code": "+81", "code": "JP" }, { "name": "Jersey", "dial_code": "+44", "code": "JE" }, { "name": "Jordan", "dial_code": "+962", "code": "JO" }, { "name": "Kazakhstan", "dial_code": "+7", "code": "KZ" }, { "name": "Kenya", "dial_code": "+254", "code": "KE" }, { "name": "Kiribati", "dial_code": "+686", "code": "KI" }, { "name": "Korea, Democratic People's Republic of Korea", "dial_code": "+850", "code": "KP" }, { "name": "Korea, Republic of South Korea", "dial_code": "+82", "code": "KR" }, { "name": "Kosovo", "dial_code": "+383", "code": "XK" }, { "name": "Kuwait", "dial_code": "+965", "code": "KW" }, { "name": "Kyrgyzstan", "dial_code": "+996", "code": "KG" }, { "name": "Laos", "dial_code": "+856", "code": "LA" }, { "name": "Latvia", "dial_code": "+371", "code": "LV" }, { "name": "Lebanon", "dial_code": "+961", "code": "LB" }, { "name": "Lesotho", "dial_code": "+266", "code": "LS" }, { "name": "Liberia", "dial_code": "+231", "code": "LR" }, { "name": "Libyan Arab Jamahiriya", "dial_code": "+218", "code": "LY" }, { "name": "Liechtenstein", "dial_code": "+423", "code": "LI" }, { "name": "Lithuania", "dial_code": "+370", "code": "LT" }, { "name": "Luxembourg", "dial_code": "+352", "code": "LU" }, { "name": "Macao", "dial_code": "+853", "code": "MO" }, { "name": "Macedonia", "dial_code": "+389", "code": "MK" }, { "name": "Madagascar", "dial_code": "+261", "code": "MG" }, { "name": "Malawi", "dial_code": "+265", "code": "MW" }, { "name": "Malaysia", "dial_code": "+60", "code": "MY" }, { "name": "Maldives", "dial_code": "+960", "code": "MV" }, { "name": "Mali", "dial_code": "+223", "code": "ML" }, { "name": "Malta", "dial_code": "+356", "code": "MT" }, { "name": "Marshall Islands", "dial_code": "+692", "code": "MH" }, { "name": "Martinique", "dial_code": "+596", "code": "MQ" }, { "name": "Mauritania", "dial_code": "+222", "code": "MR" }, { "name": "Mauritius", "dial_code": "+230", "code": "MU" }, { "name": "Mayotte", "dial_code": "+262", "code": "YT" }, { "name": "Mexico", "dial_code": "+52", "code": "MX" }, { "name": "Micronesia, Federated States of Micronesia", "dial_code": "+691", "code": "FM" }, { "name": "Moldova", "dial_code": "+373", "code": "MD" }, { "name": "Monaco", "dial_code": "+377", "code": "MC" }, { "name": "Mongolia", "dial_code": "+976", "code": "MN" }, { "name": "Montenegro", "dial_code": "+382", "code": "ME" }, { "name": "Montserrat", "dial_code": "+1664", "code": "MS" }, { "name": "Morocco", "dial_code": "+212", "code": "MA" }, { "name": "Mozambique", "dial_code": "+258", "code": "MZ" }, { "name": "Myanmar", "dial_code": "+95", "code": "MM" }, { "name": "Namibia", "dial_code": "+264", "code": "NA" }, { "name": "Nauru", "dial_code": "+674", "code": "NR" }, { "name": "Nepal", "dial_code": "+977", "code": "NP" }, { "name": "Netherlands", "dial_code": "+31", "code": "NL" }, { "name": "Netherlands Antilles", "dial_code": "+599", "code": "AN" }, { "name": "New Caledonia", "dial_code": "+687", "code": "NC" }, { "name": "New Zealand", "dial_code": "+64", "code": "NZ" }, { "name": "Nicaragua", "dial_code": "+505", "code": "NI" }, { "name": "Niger", "dial_code": "+227", "code": "NE" }, { "name": "Nigeria", "dial_code": "+234", "code": "NG" }, { "name": "Niue", "dial_code": "+683", "code": "NU" }, { "name": "Norfolk Island", "dial_code": "+672", "code": "NF" }, { "name": "Northern Mariana Islands", "dial_code": "+1670", "code": "MP" }, { "name": "Norway", "dial_code": "+47", "code": "NO" }, { "name": "Oman", "dial_code": "+968", "code": "OM" }, { "name": "Pakistan", "dial_code": "+92", "code": "PK" }, { "name": "Palau", "dial_code": "+680", "code": "PW" }, { "name": "Palestinian Territory, Occupied", "dial_code": "+970", "code": "PS" }, { "name": "Panama", "dial_code": "+507", "code": "PA" }, { "name": "Papua New Guinea", "dial_code": "+675", "code": "PG" }, { "name": "Paraguay", "dial_code": "+595", "code": "PY" }, { "name": "Peru", "dial_code": "+51", "code": "PE" }, { "name": "Philippines", "dial_code": "+63", "code": "PH" }, { "name": "Pitcairn", "dial_code": "+64", "code": "PN" }, { "name": "Poland", "dial_code": "+48", "code": "PL" }, { "name": "Portugal", "dial_code": "+351", "code": "PT" }, { "name": "Puerto Rico", "dial_code": "+1939", "code": "PR" }, { "name": "Qatar", "dial_code": "+974", "code": "QA" }, { "name": "Romania", "dial_code": "+40", "code": "RO" }, { "name": "Russia", "dial_code": "+7", "code": "RU" }, { "name": "Rwanda", "dial_code": "+250", "code": "RW" }, { "name": "Reunion", "dial_code": "+262", "code": "RE" }, { "name": "Saint Barthelemy", "dial_code": "+590", "code": "BL" }, { "name": "Saint Helena, Ascension and Tristan Da Cunha", "dial_code": "+290", "code": "SH" }, { "name": "Saint Kitts and Nevis", "dial_code": "+1869", "code": "KN" }, { "name": "Saint Lucia", "dial_code": "+1758", "code": "LC" }, { "name": "Saint Martin", "dial_code": "+590", "code": "MF" }, { "name": "Saint Pierre and Miquelon", "dial_code": "+508", "code": "PM" }, { "name": "Saint Vincent and the Grenadines", "dial_code": "+1784", "code": "VC" }, { "name": "Samoa", "dial_code": "+685", "code": "WS" }, { "name": "San Marino", "dial_code": "+378", "code": "SM" }, { "name": "Sao Tome and Principe", "dial_code": "+239", "code": "ST" }, { "name": "Saudi Arabia", "dial_code": "+966", "code": "SA" }, { "name": "Senegal", "dial_code": "+221", "code": "SN" }, { "name": "Serbia", "dial_code": "+381", "code": "RS" }, { "name": "Seychelles", "dial_code": "+248", "code": "SC" }, { "name": "Sierra Leone", "dial_code": "+232", "code": "SL" }, { "name": "Singapore", "dial_code": "+65", "code": "SG" }, { "name": "Slovakia", "dial_code": "+421", "code": "SK" }, { "name": "Slovenia", "dial_code": "+386", "code": "SI" }, { "name": "Solomon Islands", "dial_code": "+677", "code": "SB" }, { "name": "Somalia", "dial_code": "+252", "code": "SO" }, { "name": "South Africa", "dial_code": "+27", "code": "ZA" }, { "name": "South Sudan", "dial_code": "+211", "code": "SS" }, { "name": "South Georgia and the South Sandwich Islands", "dial_code": "+500", "code": "GS" }, { "name": "Spain", "dial_code": "+34", "code": "ES" }, { "name": "Sri Lanka", "dial_code": "+94", "code": "LK" }, { "name": "Sudan", "dial_code": "+249", "code": "SD" }, { "name": "Suriname", "dial_code": "+597", "code": "SR" }, { "name": "Svalbard and Jan Mayen", "dial_code": "+47", "code": "SJ" }, { "name": "Swaziland", "dial_code": "+268", "code": "SZ" }, { "name": "Sweden", "dial_code": "+46", "code": "SE" }, { "name": "Switzerland", "dial_code": "+41", "code": "CH" }, { "name": "Syrian Arab Republic", "dial_code": "+963", "code": "SY" }, { "name": "Taiwan", "dial_code": "+886", "code": "TW" }, { "name": "Tajikistan", "dial_code": "+992", "code": "TJ" }, { "name": "Tanzania, United Republic of Tanzania", "dial_code": "+255", "code": "TZ" }, { "name": "Thailand", "dial_code": "+66", "code": "TH" }, { "name": "Timor-Leste", "dial_code": "+670", "code": "TL" }, { "name": "Togo", "dial_code": "+228", "code": "TG" }, { "name": "Tokelau", "dial_code": "+690", "code": "TK" }, { "name": "Tonga", "dial_code": "+676", "code": "TO" }, { "name": "Trinidad and Tobago", "dial_code": "+1868", "code": "TT" }, { "name": "Tunisia", "dial_code": "+216", "code": "TN" }, { "name": "Turkey", "dial_code": "+90", "code": "TR" }, { "name": "Turkmenistan", "dial_code": "+993", "code": "TM" }, { "name": "Turks and Caicos Islands", "dial_code": "+1649", "code": "TC" }, { "name": "Tuvalu", "dial_code": "+688", "code": "TV" }, { "name": "Uganda", "dial_code": "+256", "code": "UG" }, { "name": "Ukraine", "dial_code": "+380", "code": "UA" }, { "name": "United Arab Emirates", "dial_code": "+971", "code": "AE" }, { "name": "United Kingdom", "dial_code": "+44", "code": "GB" }, { "name": "United States", "dial_code": "+1", "code": "US" }, { "name": "Uruguay", "dial_code": "+598", "code": "UY" }, { "name": "Uzbekistan", "dial_code": "+998", "code": "UZ" }, { "name": "Vanuatu", "dial_code": "+678", "code": "VU" }, { "name": "Venezuela, Bolivarian Republic of Venezuela", "dial_code": "+58", "code": "VE" }, { "name": "Vietnam", "dial_code": "+84", "code": "VN" }, { "name": "Virgin Islands, British", "dial_code": "+1284", "code": "VG" }, { "name": "Virgin Islands, U.S.", "dial_code": "+1340", "code": "VI" }, { "name": "Wallis and Futuna", "dial_code": "+681", "code": "WF" }, { "name": "Yemen", "dial_code": "+967", "code": "YE" }, { "name": "Zambia", "dial_code": "+260", "code": "ZM" }, { "name": "Zimbabwe", "dial_code": "+263", "code": "ZW" } ] for code in codes: file.write("\tCountryCode(name: \"{}\", dialCode: \"{}\", code: \"{}\"),\n".format(code.get("name"), code.get("dial_code"), code.get("code"))) file.write("]\n") file.close() Just run in the terminal this command: $ python3.6 file.py
I have tried to created a simpler version of the answer by Raj Joshi. class CountryCodes { struct CountryWithCode { var countryCode: String var countryName: String var dialCode: String } private static let countryDictionary = ["AF":"93", "AL":"355", "DZ":"213","AS":"1", "AD":"376", "AO":"244", "AI":"1","AG":"1","AR":"54","AM":"374","AW":"297","AU":"61","AT":"43","AZ":"994","BS":"1","BH":"973","BD":"880","BB":"1","BY":"375","BE":"32","BZ":"501","BJ":"229","BM":"1","BT":"975","BA":"387","BW":"267","BR":"55","IO":"246","BG":"359","BF":"226","BI":"257","KH":"855","CM":"237","CA":"1","CV":"238","KY":"345","CF":"236","TD":"235","CL":"56","CN":"86","CX":"61","CO":"57","KM":"269","CG":"242","CK":"682","CR":"506","HR":"385","CU":"53","CY":"537","CZ":"420","DK":"45","DJ":"253","DM":"1","DO":"1","EC":"593","EG":"20","SV":"503","GQ":"240","ER":"291","EE":"372","ET":"251","FO":"298","FJ":"679","FI":"358","FR":"33","GF":"594","PF":"689","GA":"241","GM":"220","GE":"995","DE":"49","GH":"233","GI":"350","GR":"30","GL":"299","GD":"1","GP":"590","GU":"1","GT":"502","GN":"224","GW":"245","GY":"595","HT":"509","HN":"504","HU":"36","IS":"354","IN":"91","ID":"62","IQ":"964","IE":"353","IL":"972","IT":"39","JM":"1","JP":"81","JO":"962","KZ":"77","KE":"254","KI":"686","KW":"965","KG":"996","LV":"371","LB":"961","LS":"266","LR":"231","LI":"423","LT":"370","LU":"352","MG":"261","MW":"265","MY":"60","MV":"960","ML":"223","MT":"356","MH":"692","MQ":"596","MR":"222","MU":"230","YT":"262","MX":"52","MC":"377","MN":"976","ME":"382","MS":"1","MA":"212","MM":"95","NA":"264","NR":"674","NP":"977","NL":"31","AN":"599","NC":"687","NZ":"64","NI":"505","NE":"227","NG":"234","NU":"683","NF":"672","MP":"1","NO":"47","OM":"968","PK":"92","PW":"680","PA":"507","PG":"675","PY":"595","PE":"51","PH":"63","PL":"48","PT":"351","PR":"1","QA":"974","RO":"40","RW":"250","WS":"685","SM":"378","SA":"966","SN":"221","RS":"381","SC":"248","SL":"232","SG":"65","SK":"421","SI":"386","SB":"677","ZA":"27","GS":"500","ES":"34","LK":"94","SD":"249","SR":"597","SZ":"268","SE":"46","CH":"41","TJ":"992","TH":"66","TG":"228","TK":"690","TO":"676","TT":"1","TN":"216","TR":"90","TM":"993","TC":"1","TV":"688","UG":"256","UA":"380","AE":"971","GB":"44","US":"1", "UY":"598","UZ":"998", "VU":"678", "WF":"681","YE":"967","ZM":"260","ZW":"263","BO":"591","BN":"673","CC":"61","CD":"243","CI":"225","FK":"500","GG":"44","VA":"379","HK":"852","IR":"98","IM":"44","JE":"44","KP":"850","KR":"82","LA":"856","LY":"218","MO":"853","MK":"389","FM":"691","MD":"373","MZ":"258","PS":"970","PN":"872","RE":"262","RU":"7","BL":"590","SH":"290","KN":"1","LC":"1","MF":"590","PM":"508","VC":"1","ST":"239","SO":"252","SJ":"47","SY":"963","TW":"886","TZ":"255","TL":"670","VE":"58","VN":"84","VG":"284","VI":"340"] static func values() -> [CountryWithCode] { var countriesWithCode = [CountryWithCode]() let countryCodes = countryDictionary.keys for countryCode in countryCodes { let countryName = Locale.current.localizedString(forRegionCode: countryCode) ?? "N/A" let dialCode = countryDictionary[countryCode] ?? "N/A" let countryValue = CountryWithCode(countryCode: countryCode, countryName: countryName, dialCode: dialCode) countriesWithCode.append(countryValue) } let sortedCountries = countriesWithCode.sorted { (firstCountry, secondCountry) -> Bool in let sortedByName = firstCountry.countryName.compare(secondCountry.countryName) == .orderedAscending return sortedByName } countriesWithCode.removeAll() countriesWithCode.append(contentsOf: sortedCountries) return countriesWithCode } } The above code can be implemented as: let countryCodes = CountryCodes.values() print(countryCodes.first?.dialCode)
How to create customer & items in quickbook through api in rails?
I want to create invoice in my Quickbooks account through API from my rails application, but it requires to add customer and item before creating invoice. But I can't get the idea how to add customer and items through API. Can you suggest me??? Thanks.
Start here: https://developer.intuit.com/ Follow the docs (https://developer.intuit.com/docs/0100_accounting) and implement OAuth to connect to QuickBooks Online. Create customers by HTTP POSTing a JSON request to QuickBooks Online: https://developer.intuit.com/docs/api/accounting/Customer The JSON request will look something like this: { "BillAddr": { "Line1": "123 Main Street", "City": "Mountain View", "Country": "USA", "CountrySubDivisionCode": "CA", "PostalCode": "94042" }, "Notes": "Here are other details.", "Title": "Mr", "GivenName": "James", "MiddleName": "B", "FamilyName": "King", "Suffix": "Jr", "FullyQualifiedName": "King Groceries", "CompanyName": "King Groceries", "DisplayName": "King's Groceries", "PrimaryPhone": { "FreeFormNumber": "(555) 555-5555" }, "PrimaryEmailAddr": { "Address": "jdrew#myemail.com" } } You'll get back something like this: { "Customer": { "Taxable": true, "BillAddr": { "Id": "112", "Line1": "123 Main Street", "City": "Mountain View", "Country": "USA", "CountrySubDivisionCode": "CA", "PostalCode": "94042" }, "Notes": "Here are other details.", "Job": false, "BillWithParent": false, "Balance": 0, "BalanceWithJobs": 0, "CurrencyRef": { "value": "USD", "name": "United States Dollar" }, "PreferredDeliveryMethod": "Print", "domain": "QBO", "sparse": false, "Id": "67", "SyncToken": "0", "MetaData": { "CreateTime": "2015-07-23T10:58:12-07:00", "LastUpdatedTime": "2015-07-23T10:58:12-07:00" }, "Title": "Mr", "GivenName": "James", "MiddleName": "B", "FamilyName": "King", "Suffix": "Jr", "FullyQualifiedName": "King's Groceries", "CompanyName": "King Groceries", "DisplayName": "King's Groceries", "PrintOnCheckName": "King Groceries", "Active": true, "PrimaryPhone": { "FreeFormNumber": "(555) 555-5555" }, "PrimaryEmailAddr": { "Address": "jdrew#myemail.com" }, "DefaultTaxCodeRef": { "value": "2" } }, "time": "2015-07-23T10:58:12.099-07:00" } Make sure you save that Id attribute, you'll need that later. The process for creating Items is similar. Docs: https://developer.intuit.com/docs/api/accounting/Item Everything is just standard OAuth requests. Go grab an OAuth library for Rails and you should be all set.
facebook graph api for poste is not show all data in ios
i am working one facebook intrgation project in ios,iphone so i am using me?fields=posts on browser is working properly i means on this link developer account https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=me%3Ffields%3Dposts but when i am using me?fields=posts in xcode this only return a old data not all data here is my code so please give me solution where i am doing mistake [FBRequestConnection startWithGraphPath:#"me?fields=posts" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { if (!error) { NSLog(#"Results: %#", result); NSArray *post = [result valueForKey:#"posts"]; NSArray *mainData = [post valueForKey:#"data"]; /// NSLog(#"Results: show image>>>>>>> %#", [mainData valueForKey:#"picture"]); // NSArray *picturedata =[mainData valueForKey:#"picture"]; NSLog(#"%#",picturedata); Here i attacha a image link also please check image 1 in Graph api data is { "posts": { "data": [ { "id": "100005440749818_240650716126285", "from": { "name": "Birjesh Sharma", "id": "100005440749818" }, "message": "Hello\r\n\r\n\r\n", "picture": "https://fbexternal-a.akamaihd.net/app_full_proxy.php?app=278318608948142&v=1&size=z&cksum=9c977855a08e5bde268444a1ab24a254&src=https%3A%2F%2Fraw.github.com%2Ffbsamples%2Fios-3.x-howtos%2Fmaster%2FImages%2Fiossdk_logo.png", "link": "https://developers.facebook.com/ios", "name": "Facebook SDK for iOS", "caption": "Build great social apps and get more installs.", "description": "The Facebook SDK for iOS makes it easier and faster to develop Facebook integrated iOS apps.", "icon": "https://www.facebook.com/images/litestand/bookmarks/sidebar/icons/small/icon-app.png", "actions": [ { "name": "Comment", "link": "https://www.facebook.com/100005440749818/posts/240650716126285" }, { "name": "Like", "link": "https://www.facebook.com/100005440749818/posts/240650716126285" } ], "privacy": { "description": "Friends", "value": "ALL_FRIENDS", "friends": "", "networks": "", "allow": "", "deny": "" }, "type": "link", "status_type": "app_created_story", "application": { "name": "Feed Dialog How To", "id": "278318608948142" }, "created_time": "2014-04-26T12:59:15+0000", "updated_time": "2014-04-26T12:59:15+0000" }, { "id": "100005440749818_240650712792952", "from": { "name": "Birjesh Sharma", "id": "100005440749818" }, "message": "Hello\r\n\r\n\r\n", "picture": "https://fbexternal-a.akamaihd.net/app_full_proxy.php?app=278318608948142&v=1&size=z&cksum=9c977855a08e5bde268444a1ab24a254&src=https%3A%2F%2Fraw.github.com%2Ffbsamples%2Fios-3.x-howtos%2Fmaster%2FImages%2Fiossdk_logo.png", "link": "https://developers.facebook.com/ios", "name": "Facebook SDK for iOS", "caption": "Build great social apps and get more installs.", "description": "The Facebook SDK for iOS makes it easier and faster to develop Facebook integrated iOS apps.", "icon": "https://www.facebook.com/images/litestand/bookmarks/sidebar/icons/small/icon-app.png", "actions": [ { "name": "Comment", "link": "https://www.facebook.com/100005440749818/posts/240650712792952" }, { "name": "Like", "link": "https://www.facebook.com/100005440749818/posts/240650712792952" } ], "privacy": { "description": "Friends", "value": "ALL_FRIENDS", "friends": "", "networks": "", "allow": "", "deny": "" }, "type": "link", "status_type": "app_created_story", "application": { "name": "Feed Dialog How To", "id": "278318608948142" }, "created_time": "2014-04-26T12:59:14+0000", "updated_time": "2014-04-26T12:59:14+0000" }, { "id": "100005440749818_240643612793662", "from": { "name": "Birjesh Sharma", "id": "100005440749818" }, "message": "Hello how are you", "actions": [ { "name": "Comment", "link": "https://www.facebook.com/100005440749818/posts/240643612793662" }, { "name": "Like", "link": "https://www.facebook.com/100005440749818/posts/240643612793662" } ], "privacy": { "description": "Friends", "value": "ALL_FRIENDS", "friends": "", "networks": "", "allow": "", "deny": "" }, "type": "status", "status_type": "mobile_status_update", "application": { "name": "Batch Requests How To", "id": "216458921816803" }, "created_time": "2014-04-26T12:20:43+0000", "updated_time": "2014-04-26T12:20:43+0000" }, { "id": "100005440749818_240368252821198", "from": { "name": "Birjesh Sharma", "id": "100005440749818" }, "story": "Birjesh Sharma added a new photo.", "picture": "https://fbcdn-photos-e-a.akamaihd.net/hphotos-ak-prn2/t1.0-0/10155869_240368246154532_637168545169195821_s.jpg", "link": "https://www.facebook.com/photo.php?fbid=240368246154532&set=a.170520606472630.1073741830.100005440749818&type=1&relevant_count=1", "name": "HelloFBSample Photos", "icon": "https://fbstatic-a.akamaihd.net/rsrc.php/v2/yz/r/StEh3RhPvjk.gif", "actions": [ { "name": "Comment", "link": "https://www.facebook.com/100005440749818/posts/240368252821198" }, { "name": "Like", "link": "https://www.facebook.com/100005440749818/posts/240368252821198" } ], "privacy": { "description": "Only Me", "value": "SELF", "friends": "", "networks": "", "allow": "", "deny": "" }, "type": "photo", "status_type": "added_photos", "object_id": "240368246154532", "application": { "name": "HelloFBSample", "namespace": "fbsdktemplateapp", "id": "355198514515820" }, "created_time": "2014-04-25T13:26:06+0000", "updated_time": "2014-04-25T13:26:06+0000" }, { "id": "100005440749818_240333912824632", "from": { "name": "Birjesh Sharma", "id": "100005440749818" }, "message": "Post by nishant", "picture": "https://fbcdn-photos-f-a.akamaihd.net/hphotos-ak-prn2/t1.0-0/10155899_240333846157972_3108893745639530212_s.jpg", "link": "https://www.facebook.com/photo.php?fbid=240333846157972&set=a.239581289566561.1073741833.100005440749818&type=1&relevant_count=1", "icon": "https://fbstatic-a.akamaihd.net/rsrc.php/v2/yz/r/StEh3RhPvjk.gif", "actions": [ { "name": "Comment", "link": "https://www.facebook.com/100005440749818/posts/240333912824632" }, { "name": "Like", "link": "https://www.facebook.com/100005440749818/posts/240333912824632" } ], "privacy": { "description": "Public", "value": "EVERYONE", "friends": "", "networks": "", "allow": "", "deny": "" }, "type": "photo", "status_type": "added_photos", "object_id": "240333846157972", "created_time": "2014-04-25T10:33:45+0000", "updated_time": "2014-04-25T10:33:45+0000", "likes": { "data": [ { "id": "100005440749818", "name": "Birjesh Sharma" } ], "paging": { "cursors": { "after": "MTAwMDA1NDQwNzQ5ODE4", "before": "MTAwMDA1NDQwNzQ5ODE4" } } } }, and when i am using this graph api in xcode the data show this Results: { id = 100005440749818; posts = { data = ( { "created_time" = "2014-04-17T14:13:12+0000"; from = { id = 100005440749818; name = "Birjesh Sharma"; }; id = "100005440749818_238353183022705"; link = "https://www.facebook.com/nitin.dhiran.1?fref=nf_fr"; picture = "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/t1.0-1/c0.9.50.50/p50x50/10262125_697172320343788_6250762651875413687_t.jpg"; privacy = { value = ""; }; "status_type" = "approved_friend"; story = "Birjesh Sharma is now friends with Nitin Dhiran and 3 other people."; "story_tags" = { 0 = ( { id = 100005440749818; length = 14; name = "Birjesh Sharma"; offset = 0; type = user; } ); 35 = ( { id = 100001530793389; length = 12; name = "Nitin Dhiran"; offset = 35; type = user; } ); 52 = ( { id = 100008058972523; length = 14; name = "Hemant Kumar"; offset = 52; type = user; }, { id = 100001307401657; length = 14; name = "Chetan Pushpad"; offset = 52; type = user; }, { id = 100002675972915; length = 14; name = "Vipin Shukla"; offset = 52; type = user; } ); }; type = link; "updated_time" = "2014-04-17T14:13:12+0000"; }, { "created_time" = "2014-03-27T07:21:35+0000"; from = { id = 100005440749818; name = "Birjesh Sharma"; }; id = "100005440749818_232528183605205"; privacy = { value = ""; }; "status_type" = "approved_friend"; story = "Birjesh Sharma is now friends with Ishant Tiwari and Viraj Dongre."; "story_tags" = { 0 = ( { id = 100005440749818; length = 14; name = "Birjesh Sharma"; offset = 0; type = user; } ); 35 = ( { id = 100000329153640; length = 13; name = "Ishant Tiwari"; offset = 35; type = user; } ); 53 = ( { id = 100002123975517; length = 12; name = "Viraj Dongre"; offset = 53; type = user; } ); }; type = status; "updated_time" = "2014-03-27T07:21:35+0000"; } ); paging = { next = "https://graph.facebook.com/100005440749818/posts?access_token=CAAUTJQ2n428BAN3p9kiFFMZA7ZBlDO2NTIddfkUNJdbqT32kfbVs8GJaORmJXTF4NnF6RUtIwwp0H0vTzS147lxFF3runTHbupqZBkxbyl73dV5URHwvZA78CqVXWJggaofAy2JfZBf1GCoUQfNCyN0TAJaEnnsLn9ea6d2wLtDAataFtxGyFQJwZBWajQOiIwtidXqliCFV8haorHgfE4ahdbpO5n7oUZD&limit=25&until=1395904894"; previous = "https://graph.facebook.com/100005440749818/posts?access_token=CAAUTJQ2n428BAN3p9kiFFMZA7ZBlDO2NTIddfkUNJdbqT32kfbVs8GJaORmJXTF4NnF6RUtIwwp0H0vTzS147lxFF3runTHbupqZBkxbyl73dV5URHwvZA78CqVXWJggaofAy2JfZBf1GCoUQfNCyN0TAJaEnnsLn9ea6d2wLtDAataFtxGyFQJwZBWajQOiIwtidXqliCFV8haorHgfE4ahdbpO5n7oUZD&limit=25&since=1397743992&__previous=1"; }; }; }
The posts list is divided into several pages, and you only got the first page. To get all the posts, use the URL in results.posts.paging.next. You can use this FBSDKGraphRequest paging extension to do that for you.
Rails - better flow control - loop
I am grabbing value data: name, uid, highschool_name, graduateschool_name like this: def add_friends facebook.get_connections("me", "friends", :fields => "name, id, education").each do |hash| self.friends.where(:name => hash['name'], :uid => hash['id'], :highschool_name => hash['education']['school']['name'] unless hash["education"].blank?, :graduateschool_name => hash['education']['school']['name'] unless hash["education"].blank?). first_or_create end end From an array of hash: "education": [ { "school": { "id": "110703012290674", "name": "Kunskapsgymnasiet Malmö" }, "year": { "id": "136328419721520", "name": "2009" }, "type": "High School" }, { "school": { "id": "112812485399398", "name": "Malmö University" }, "year": { "id": "118118634930920", "name": "2012" }, "concentration": [ { "id": "104076956295773", "name": "Computer Science" } ], "type": "Graduate School", "classes": [ { "id": "165093923542525", "name": "Programmering", "description": "Kursen fokuserar på metoder och tekniker vid utveckling av webbapplikationer med hjälp av HTML5." } ] } ], EDIT: This code dosent work. I would like to pick every hichschool and Graduate School from this array of hash and save it.
high_schools = response['education'].collect{|ed| ed['school']['name'] if ed['type'] == "High School" } grad_schools = response['education'].collect{|ed| ed['school']['name'] if ed['type'] == "Graduate School" }