简体   繁体   English

通过编程方式检测iPhone中是否有Sim卡可用

[英]Detect if Sim Card is available in iPhone programmatically

Hi I am Working on SMSComposer and want to send SMS to Contacts from Address Book.I want to detect whether my iPhone has SIM Card in it or not 您好我正在使用SMSComposer,并希望通过地址簿向联系人发送短信。我想检测我的iPhone是否有SIM卡

Is there any way i can reach this.? 有什么方法可以达到这个目的。

I tried REachability Classes but it gives you information about WWAN and internet Connectivity.Does Core Telephony Framework has such Facility.? 我尝试了REachability Classes,但它为您提供有关WWAN和Internet Connectivity的信息。核心电话框架有这样的设施。 Something Like Carrier NAme etc for iPhone.?? 像iPhone这样的Carrier NAme等。

Any help would be appreciated. 任何帮助,将不胜感激。 Thanks Vikas 谢谢Vikas

try to link the CoreTelephony.framework then: 尝试链接CoreTelephony.framework然后:

#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <CoreTelephony/CTCarrier.h>

NSString *_code = [[[[CTTelephonyNetworkInfo alloc] init] subscriberCellularProvider] mobileCountryCode];

you can find more information in the official documentation about that but briefly: 您可以在官方文档中找到有关该信息的更多信息,但简要说明:

The value for this property is nil if any of the following applies: 如果符合以下任何条件,则此属性的值为nil

  • There is no SIM card in the device. 设备中没有SIM卡。

  • The device is outside of cellular service range. 该设备不在蜂窝服务范围内。

The value may be nil on hardware prior to iPhone 4S when in Airplane mode. 在飞行模式下,iPhone 4S之前的硬件上的值可能nil

For this purpose you need to add MessageUI.framework framework... 为此,您需要添加MessageUI.framework框架...

Try this code...It may help you 试试这个代码...它可能对你有帮助

Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));
if([messageClass canSendText]){
    // Sim available
}
else{
    //Sim not available
}

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

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