0

I need help... I am new to iPhone app development and working on a registration page. Scenario:->

  1. Location services is off.
  2. Two text fields, one for phone country code and other for phone number.
  3. When registration page pops up, country code should be automatically filled with the country code of the device.

Problem:-> I am having difficulty in fetching the country code from device information. Also, what info may I use for the same... IMEI, MDN, Locale, etc...


Any response is appreciated..!

  • 2
    Possible duplicate of [How to get Mobile Country and Network code on an iPhone](https://stackoverflow.com/questions/2559449/how-to-get-mobile-country-and-network-code-on-an-iphone) – nathan Aug 24 '17 at 14:12
  • How do you appreciate the responses so far? – meaning-matters Aug 24 '17 at 22:01

1 Answers1

0

You can get this information from iOS' CoreTelephony framework:

#import <CoreTelephony/CTTelephonyNetworkInfo.h>

...

@property (nonatomic, strong) CTTelephonyNetworkInfo* networkInfo;

...

self.networkInfo = [[CTTelephonyNetworkInfo alloc] init];

NSString* country = [self.networkInfo subscriberCellularProvider].isoCountryCode;

I quickly copy-pasted this from one of my apps. I trust you can convert this to Swift if you need to.

subscriberCellularProvider gives access to the CTCarrier object, which has more fields than just the country code: MCC, MNC, carrier name, and a flag if VoIP is allowed.

iOS does not give access to IMEI.

The In App Purchase APIs can tell you on which iTunes Store the user is; an ISO country code again. You probably need to have IAP activated for your app, so when you don't sell anything, this may not be allowed/an option.

The current locale can indeed also give you a country code:

let locale  = NSLocale.currentLocale()
let country = currentLocale.objectForKey(NSLocaleCountryCode) as? String 
meaning-matters
  • 21,929
  • 10
  • 82
  • 142