(1) 检测iPhone是否插入Sim卡
1. 首先在判断是否插入Sim卡方法的.h文件中粘贴如下代码
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,NSString* number,NSString* text);
void * CTSMSMessageCreateReply(void* unknow,void * forwardTo,NSString* text);
void* CTSMSMessageSend(id server,id msg);
NSString *CTSMSMessageCopyAddress(void *, void *);
NSString *CTSMSMessageCopyText(void *, void *);
2. 导入CTTelephony.framework
3. 在.m文件中调用方法判断:
BOOL noSim=[CTSIMSupportGetSIMStatus() isEqualToString:kCTSIMSupportSIMStatusNotInserted];
NSLog(@"no Sim %@",noSim?@"YES":@"NO");
如果结果是YES表示没有插入Sim卡,如果是NO则表示插入了Sim卡
(2)插入拔出Sim卡事件监听方法
NSString *CTSIMSupportGetSimStatus();
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(SIMNotification:) name:@"kCTSIMSupportSIMStatusChangeNotification" object:nil];
然后定义相应方法SIMNotification
-(void)SIMNotification:(id)selector{
[self showSimInfo];
}
拔出Sim卡时调用一次,插入Sim卡也调用一次