简体   繁体   English

如何检查是否安装了SIM卡

[英]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" 我正在开发一个具有呼叫和消息功能的应用程序,我想检查是否安装了SIM卡因为它发出了“消息已发送成功”的警报

Please help me out. 请帮帮我。

There might be different ways but one way is by using MFMessageComposeViewController class to see if you can send the text message. 可能有不同的方法,但一种方法是使用MFMessageComposeViewController类来查看是否可以发送文本消息。 If you can then sim is available otherwise not. 如果你可以然后sim可用,否则不可用。

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. 如果您有iMessage可用,那么这可能会返回true,您也可以检查是否可以进行调用,您可能希望将CTTelephonyNetworkInfo用于此目的。

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 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: 如果符合以下任何条件,则此属性的值为nil:

The device is in Airplane mode. 设备处于飞行模式。 There is no SIM card in the device. 设备中没有SIM卡。 The device is outside of cellular service range. 该设备不在蜂窝服务范围内。

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............ 首先你必须确定设备是iPhone(不是iPod或iPad),然后检查设备是否可以拨打电话,就像这样............

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........ 希望它会帮助你........

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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