Identifying the country code using mobile carrier in iPhone programmatically?

后端 未结 2 591
伪装坚强ぢ
伪装坚强ぢ 2020-12-30 15:57

Is there any way to get the country code from mobile network. Can we get the country name of the SIM present in the Device through code?

Please Help me out in this w

相关标签:
2条回答
  • 2020-12-30 16:18

    EDIT: With Xcode 6, simply add this line, even linking the framework to the project is done automatically:

    @import CoreTelephony;
    

    original: Add CoreTelephony.framework to your project. inside your class add this two lines:

    #import <CoreTelephony/CTCarrier.h>
    #import <CoreTelephony/CTTelephonyNetworkInfo.h>
    

    this is the code:

    CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
    CTCarrier *carrier = [networkInfo subscriberCellularProvider];
    
    
    // Get carrier name
    NSString *carrierName = [carrier carrierName];
    if (carrierName != nil)
        NSLog(@"Carrier: %@", carrierName);
    
    // Get mobile country code
    NSString *mcc = [carrier mobileCountryCode];
    if (mcc != nil)
        NSLog(@"Mobile Country Code (MCC): %@", mcc);
    
    // Get mobile network code
    NSString *mnc = [carrier mobileNetworkCode];
    
    if (mnc != nil)
        NSLog(@"Mobile Network Code (MNC): %@", mnc);
    

    Note that country code is in numeric code you can find the list here

    0 讨论(0)
  • 2020-12-30 16:25

    It is inside CoreTelephony

    CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
    CTCarrier *carrier = [networkInfo subscriberCellularProvider];
    
    0 讨论(0)
提交回复
热议问题