I am developing an iOS app in which the user enters their mobile number. How do I get their country calling code? For example, if a user is in India, then +91
should be prefixed automatically. Is there an option that adds country codes automatically?
Go to Product -> Scheme -> Edit Scheme... -> Run -> Options and choose the Application Language and Application Region you want to test.
getCountry(Locale. getDefault()); System. out. println("country = "+locale);
Calling the USA: +1 is the US Country Code.
This happens when there is a mismatch between the number associated with the conversation in Messages and the number associated with the person in Contacts.
Import Statement :
#import<CoreTelephony/CTCarrier.h> #import <CoreTelephony/CTTelephonyNetworkInfo.h>
you can get country code for the current Carrier using CoreTelephony framework:
CTTelephonyNetworkInfo *network_Info = [CTTelephonyNetworkInfo new]; CTCarrier *carrier = network_Info.subscriberCellularProvider; NSLog(@"country code is: %@", carrier.mobileCountryCode); //will return the actual country code NSLog(@"ISO country code is: %@", carrier.isoCountryCode);
Apple Docs
with the use of NSLocale
you can get the country name, code etc. Take a look at below code it will help you to do so.
NSLocale *currentLocale = [NSLocale currentLocale]; // get the current locale. NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode]; // get country code, e.g. ES (Spain), FR (France), etc.
for a countries dialing code you can visit this reference code.
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