2

I am developing an app which has call and message functionality , i want to check if sim card is installed or not coz i am facing problem with messaging as it gives alerts for " Message Sent Successful"

Please help me out.

mattt
  • 19,544
  • 7
  • 73
  • 84
Himanshu
  • 321
  • 1
  • 4
  • 19
  • I think you wanna Detecting SIM card availability.Am i right ? – Dharmbir Singh Apr 23 '13 at 10:06
  • You should not do this, since you app can also run on a iPad WiFi or iPod touch which do not hold sim cards. `MFMessageComposeViewController` has a class method `canSendText ` which will indicate if the device is able to send messages. For check if the device support calling just check wether the `call:` can be opened. – rckoenes Apr 23 '13 at 10:10

3 Answers3

5

There might be different ways but one way is by using MFMessageComposeViewController class to see if you can send the text message. If you can then sim is available otherwise not.

if ([MFMessageComposeViewController canSendText]) {
    NSLog(@"SIM Available");
} else {
    NSLog(@"no SIM card installed");
}

In cases you have iMessage available then this might return you true, you could also check if you can make a call, you might want to use CTTelephonyNetworkInfo for that purpose.

badhanganesh
  • 3,427
  • 3
  • 18
  • 39
nsgulliver
  • 12,655
  • 23
  • 43
  • 64
  • I am checking like this if the sim is installed or not, it works fine. but i am getting alert message "Cannot Send Message" "Text message is not available in x device". How can i prevent that kind of alert message??? @nsgulliver – S P Balu Kommuri Feb 03 '15 at 06:06
  • This code is useful for if you use simulator. Not in a phone. – Poles Nov 27 '15 at 07:16
  • @nsgulliver, `canSendText` is called but I am getting 'MessageComposeResultFailed' status if sim not inserted in my device. and If I inserted sim in one of my device and send message successfully.I got confused is sim card is necessary for the 'MFMessageComposeViewController' to send a message successfully?can you please explain it. – Shangari C Apr 18 '16 at 11:55
4

You can also check using like this.... First read this doc

http://developer.apple.com/library/ios/#DOCUMENTATION/NetworkingInternet/Reference/CTCarrier/Reference/Reference.html#//apple_ref/doc/uid/TP40009596-CH1-SW1

NSString *_code = [[[CTCarrier alloc] init] mobileCountryCode];

The value for this property is nil if any of the following apply:

The device is in Airplane mode. There is no SIM card in the device. The device is outside of cellular service range.

Dharmbir Singh
  • 17,485
  • 5
  • 50
  • 66
1

First you have to be sure that device is iPhone (not iPod or iPad) then check if device can make call or not, just like this............

if([[UIDevice currentDevice].model isEqualToString:@"iPhone"])
{
     if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel:123456"]])
     {
         NSLog(@"Device can make call or send message");
     }
     else
     {
         NSLog(@"Device can not make call or send message");
     }
}
else
{
    NSLog(@"Device can not make call or send message");
}

Hope it will help you........

Nirav Gadhiya
  • 6,342
  • 2
  • 37
  • 76