Himanshu
Himanshu

Reputation: 321

How to check if sim card is installed or not

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.

Upvotes: 2

Views: 5925

Answers (3)

nsgulliver
nsgulliver

Reputation: 12671

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.

Upvotes: 5

Nirav Gadhiya
Nirav Gadhiya

Reputation: 6342

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........

Upvotes: 1

Dharmbir Singh
Dharmbir Singh

Reputation: 17535

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.

Upvotes: 4

Related Questions