I'm quite new to iOS development and I'm currently building my first app. I'm trying to get a text field to automatically populate the telephone country code for a specific country.
So if for example the user picks "UK" he gets "+44" inserted automatically into that text field.
Currently I'm struggling a way to find how to get the exact country telephone code for the country. I could create an NSDictionary with all of the countries and country telephone code but I thought there might be a better way.
If your goal is to get the dialling code of the user's current location then you should use HMDiallingCode.
It uses CoreLocation and reverse geocoding to get current country of the user and then retrieve it's dialling code.
I think, you can only get country code for the current Carrier using CoreTelephony framework:
CTTelephonyNetworkInfo *info = [CTTelephonyNetworkInfo new];
CTCarrier *carrier = info.subscriberCellularProvider;
NSLog(@"country code is: %@", carrier.mobileCountryCode);
If you need a full list of codes for all countries, you need to use some online service for querying it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With