Retrieving a country telephone code for a specific country in iOS

前端 未结 4 761
深忆病人
深忆病人 2021-02-04 21:35

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 c

4条回答
  •  轮回少年
    2021-02-04 22:00

    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.

提交回复
热议问题