新出的Iphonexs iphonexr都支持了双卡,那么如何通过代码读取手机里有几张sim卡?
在IOS中想要读取SIM卡的信息都要引入 “CoreTelephony”框架,引入相关头文件#import<CoreTelephony/CTTelephonyNetworkInfo.h> #import<CoreTelephony/CTCarrier.h>
-(int)judgeNumOfSimCardInPhone{
CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
if(@available(iOS12.0, *)) {
NSDictionary *ctDict = networkInfo.serviceSubscriberCellularProviders;
if([ctDictallKeys].count>1){
NSArray*keys = [ctDictallKeys];
CTCarrier*carrier1 = [ctDictobjectForKey:keys[0]];
CTCarrier*carrier2 = [ctDictobjectForKey:keys[1]];
if(carrier1.mobileCountryCode.length && carrier2.mobileCountryCode.length){
return2;
}else if(!carrier1.mobileCountryCode.length && !carrier2.mobileCountryCode.length){
return0;
}else{
return1;
}
}elseif([ctDictallKeys].count==1){
NSArray*keys = [ctDictallKeys];
CTCarrier*carrier1 = [ctDictobjectForKey:keys[0]];
if(carrier1.mobileCountryCode.length){
return1;
}else{
return0;
}
}else{
return0;
}
}else{
CTCarrier*carrier = [networkInfosubscriberCellularProvider];
NSString*name = carrier.mobileCountryCode;
if(name.length){
return1;
}else{
return0;
}
}
}