标签:
判断 iPhone 是否插入了 SIM 卡,可以参考苹果官网的 systemconfigure framework 教程,将下面的代码复制到头文件
#import <Foundation/Foundation.h> @interface NSObjectiveCPlusPLus : NSObject extern NSString* const kCTSMSMessageReceivedNotification; extern NSString* const kCTSMSMessageReplaceReceivedNotification; extern NSString* const kCTSIMSupportSIMStatusNotInserted; extern NSString* const kCTSIMSupportSIMStatusReady; id CTTelephonyCenterGetDefault(void); void CTTelephonyCenterAddObserver(id,id,CFNotificationCallback,NSString*,void*,int); void CTTelephonyCenterRemoveObserver(id,id,NSString*,void*); int CTSMSMessageGetUnreadCount(void); int CTSMSMessageGetRecordIdentifier(void * msg); NSString * CTSIMSupportGetSIMStatus(); NSString * CTSIMSupportCopyMobileSubscriberIdentity(); id CTSMSMessageCreate(void* unknow/*always 0*/,NSString* number,NSString* text); void * CTSMSMessageCreateReply(void* unknow/*always 0*/,void * forwardTo,NSString* text); void* CTSMSMessageSend(id server,id msg); NSString *CTSMSMessageCopyAddress(void *, void *); NSString *CTSMSMessageCopyText(void *, void *); @end
然后引入 CoreTelephony.framework ,即可利用 [CTSIMSupportGetSIMStatus() isEqualToString:kCTSIMSupportSIMStatusNotInserted] 进行判断。
用法:
//判断是否插入 if simStatus.isEqualToString(kCTSIMSupportSIMStatusNotInserted) { //未插入SIM卡 }else { //拨打电话 var urlString = "tel:" + businessDetailModel.serviceTel! UIApplication.sharedApplication().openURL(NSURL(string: urlString)!) }
标签:
原文地址:http://my.oschina.net/u/2253117/blog/488624