简体   繁体   中英

iOS : Check whether the phone is dual SIM?

In Android we can detect whether the phone is Single SIM or Dual SIM. And as we know iPhone XS, iPhone XS Max, iPhone XR, and later feature Dual SIM with a nano-SIM and an eSIM except china mainland where there is no eSIM.

A) I can programatically invoke MFMessageComposeViewController from a button click to send the SMS to a particular number. Here is the following code: This code can tell us whether the SIM is inserted or not. But will it work for eSIM too?

-(void)openMessageViewWithName:(NSString*)contactName withPhone:(NSString *)phone{

CTTelephonyNetworkInfo *networkInfo=[[CTTelephonyNetworkInfo alloc]init];

CTCarrier *carrier=networkInfo.subscriberCellularProvider;

NSString *Countrycode = carrier.isoCountryCode;

if ([Countrycode length]>0)     //Check If Sim Inserted
{

    [self sendSMS:msg recipientList:[NSMutableArray arrayWithObject:phone]];
}
else
{

    [AlertHelper showAlert:@"Message" withMessage:@"No sim card inserted"];
}

//Method for sending message:

   - (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSMutableArray *)recipients{  
 MFMessageComposeViewController *controller1 = [[MFMessageComposeViewController alloc] init] ;
 controller1 = [[MFMessageComposeViewController alloc] init] ;
 if([MFMessageComposeViewController canSendText])
{
    controller1.body = bodyOfMessage;
    controller1.recipients = recipients;
    controller1.messageComposeDelegate = self;
    [self presentViewController:controller1 animated:YES completion:Nil];
 }
}

B) Is it possible to determine whether my iPhone is Dual SIM or Single SIM programatically? If yes it is DUAL SIM then can we choose the SIM from my application to send the SMS?

Please help me with these and help me with a workaround.

As @PaulW11 mentioned in comment "No, you cannot detect sim details nor select the sim that is used to send messages. This is controlled by the user " Read Carefully for understanding

A) First of all no SIM related datas or phone number you are going to get in iOS, the only details you get is regarding the.network like carriername,mobilecountrycode,isocountrycode,mobil.networkcode. So if you replace a Verizon SIM with Verizon you will see the carrier name as Verizon only, nothing else you are going to get

SOLUTION Invoke MFMessageController from a button click as you are doing.This opens the iOS default SMS/Messages app. Then allow the user to choose the SIM in case of Dual SIM from the Messages App itself.

B) It is not possible to select the particular SIM/Phone Number inside your application. Because there is no provision in iOS to do that as in Android. Instead you must invoke the default messages app in iOS where you can choose your desired SIM (in case of DUAL sim) for sending SMS or else in case of single SIM it directly sends the message from that number

did you try this?

    CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc]init];
    if (@available(iOS 12.0, *)) {
        NSDictionary *providers = [networkInfo serviceSubscriberCellularProviders];
        NSEnumerator *e = [providers objectEnumerator];
        if ([[e.allObjects firstObject] isKindOfClass:(CTCarrier.class)]) {
            NSString *str = ((CTCarrier *)[e.allObjects firstObject]).isoCountryCode;
        }
    } else {
        // do a fallback
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM