IOS, how to find the country code, user phone number?

I have an application that needs to find out the country code on the phone number that the user has. I understand that I can’t just get the user's phone number, but is there a way, for example, if I have a phone number in the USA to get the country code +1?

I found several answers stating that using basic telephony you can get the country code "+1", but I tried several, and none of them work.

I tried this:

CTTelephonyNetworkInfo *network_Info = [CTTelephonyNetworkInfo new]; CTCarrier *carrier = network_Info.subscriberCellularProvider; NSString *mnc = [carrier mobileNetworkCode]; NSString *mcc = [carrier mobileCountryCode]; NSLog(@"country code is: %@, mnc: %@, mcc: %@", carrier.mobileCountryCode, mnc, mcc); 

which prints:

 "country code is: 310, mnc: 410, mcc: 310" 

So, for an American number, I would like to get +1.

Is there any way to do this?

EDIT: On a further search, I found this:

How to match MCC + MNC with the country code of a user's phone in iOS objective-C without using location information?

This might do the trick, but I was looking for a more formal way to do it.

+6
source share
1 answer

The country code can be obtained using:

 NSString *cc = [carrier isoCountryCode]; 

That will give you the US for the American device. You can match the country code with the country code using the JSON data available on this .

+8
source

Source: https://habr.com/ru/post/973254/


All Articles