iOS obtains the IMSI information of the mobile card

In daily development, we need to make some restrictions on user login, make some unique identification for users, or login without password.

Generally, methods such as obtaining UUID, UDID, IDFA..., etc., are not guaranteed to be unique. A more reliable method is to use the keychain (keyChain) to save the UUID and take it from the keyChain every time.

However, some projects of the company want to use the information of the mobile phone card to log in without secret to ensure the uniqueness of the user. Android can directly read the IMSI information. As long as the card is changed to a new mobile phone, the same can be used to log in, without being restricted by the device. Up.

1. What is IMSI information

Glossary 
IMSI: International Mobile Subscriber Identification Number International Mobile Subscriber Identification Number.

IMSI has 15 digits and its structure is as follows:

MCC + MNC + MSIN , (MNC + MSIN = NMSI)

 MCC: Mobile Country Code, the mobile country code, MCC resources are uniformly allocated and managed by the International Telecommunications Union (ITU), which uniquely identifies the country to which the mobile user belongs. There are 3 digits in total, and China is 460;

MNC: Mobile Network Code, mobile network code, a total of 2 digits, China Mobile TD system uses 00, China Unicom GSM system uses 01, China Mobile GSM system uses 02, China Telecom CDMA system uses 03, a typical IMSI number is 460030912121001;

MSIN: Mobile Subscriber Identification Number has 10 digits and its structure is as follows:

09 + M0M1M2M3 + ABCD

M0M1M2M3 and H0H1H2H3 in the MDN number can have a corresponding relationship, and the four ABCD bits are freely allocated.

In this way, the operator can be determined based on the MCC and MNC in IMSI. Of course, knowing the coding rules also needs to know the country and network corresponding to the coding.

Note : In fact, Apple pays great attention to privacy protection, so the provided api cannot get all 15 bits, only part of the information can be obtained, as follows

2. Specific code method

1. Import the header file

#import <CoreTelephony/CTCarrier.h>

#import <CoreTelephony/CTTelephonyNetworkInfo.h>

2. How to Obtain

- (NSDictionary *)getIMSIInfo{
    CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];
    CTCarrier *carrier = nil;
    NSString *radioType = nil;
    if (@available(iOS 12.1, *)) {

        if (info && [info respondsToSelector:@selector(serviceSubscriberCellularProviders)]) {

            NSDictionary *dic = [info serviceSubscriberCellularProviders];
            if (dic.allKeys.count) {
                carrier = [dic objectForKey:dic.allKeys[0]];
            }
        }

        if (info && [info respondsToSelector:@selector(serviceCurrentRadioAccessTechnology)]) {

            NSDictionary *radioDic = [info serviceCurrentRadioAccessTechnology];
            if (radioDic.allKeys.count) {
                radioType = [radioDic objectForKey:radioDic.allKeys[0]];
            }
        }

    }

    //运营商可用
    BOOL use = carrier.allowsVOIP;
    //运营商名字
    NSString *name = carrier.carrierName;
    //ISO国家代码
    NSString *code = carrier.isoCountryCode;
    //移动国家代码
    NSString *mcc = [carrier mobileCountryCode];
    //移动网络代码
    NSString *mnc = [carrier mobileNetworkCode];
	 NSDictionary *dict =@{
		@"name":name,@"code":code,@"mcc":mcc,@"mnc":mnc
	};
	NSLog(@"运营商名字:%@,ISO国家代码:%@,移动国家代码:%@,移动网络代码:%@",name,code,mcc,mnc);
	return dict;
}

We only have these attributes when we enter the system CTCarrier, as shown below

3. Summary:

It is not complete for iOS to obtain the IMSI information of the mobile phone card. Only part of the information can be obtained. Therefore, if you want to use the IMSI as the binding user, as the only sign, the password-free login is not feasible. You can only think of other ways.

I hope Apple can update the api in this regard in the future.

 

 

Guess you like

Origin blog.csdn.net/zjpjay/article/details/108636273