C++代碼
//externidallIncomingMessages; //externintincomingMessageCount; externNSString*constkCTSMSMessageReceivedNotification; externNSString*constkCTSMSMessageReplaceReceivedNotification; externNSString*constkCTSIMSupportSIMStatusNotInserted; externNSString*constkCTSIMSupportSIMStatusReady; //typedefstruct_CTCallCTCall; externNSString*CTCallCopyAddress(void*,CTCall*); void*CTSMSMessageSend(idserver,idmsg); typedefstruct__CTSMSMessageCTSMSMessage; NSString*CTSMSMessageCopyAddress(void*,CTSMSMessage*); NSString*CTSMSMessageCopyText(void*,CTSMSMessage*); intCTSMSMessageGetRecordIdentifier(void*msg); NSString*CTSIMSupportGetSIMStatus(); NSString*CTSIMSupportCopyMobileSubscriberIdentity(); idCTSMSMessageCreate(void*unknow/*always0*/,NSString*number,NSString*text); void*CTSMSMessageCreateReply(void*unknow/*always0*/,void*forwardTo,NSString*text); idCTTelephonyCenterGetDefault(void); voidCTTelephonyCenterAddObserver(id,id,CFNotificationCallback,NSString*,void*,int); voidCTTelephonyCenterRemoveObserver(id,id,NSString*,void*); intCTSMSMessageGetUnreadCount(void);引用 回調函數:
C++代碼
staticvoidcallback(CFNotificationCenterRefcenter,void*observer,CFStringRefname,constvoid*object,CFDictionaryRefuserInfo){
//NSLog(@"%@",name);
NSString*strNotficationName=(NSString*)name;
if([strNotficationNameisEqualToString:@"kCTMessageReceivedNotification"]){
inta=0;
}
//NSAutoreleasePool*pool=[[NSAutoreleasePoolalloc]init];
@synchronized(nil){
if(!userInfo)return;
if([[(NSDictionary*)userInfoallKeys]
containsObject:@"kCTMessageIdKey"])//SMSMessage
{
NSDictionary*info=(NSDictionary*)userInfo;
CFNumberRefmsgID=(CFNumberRef)[infoobjectForKey:@"kCTMessageTypeKey"];
intresult;
CFNumberGetValue((CFNumberRef)msgID,kCFNumberSInt32Type,&result);
ClassCTTelephonyCenter=NSClassFromString(@"CTTelephonyCenter");
ClassCTMessageCenter=NSClassFromString(@"CTMessageCenter");
idmc=[CTMessageCentersharedMessageCenter];
intcount=[mcincomingMessageCount];
idmcarr=[mcallIncomingMessages];
//idincMsg=[mcincomingMessageWithId:result];
//if(count==0){
//return;
//}
idincMsg=[[mcallIncomingMessages]objectAtIndex:0];
intmsgType=(int)[incMsgmessageType];
if(msgType==1)//experimentallydetectednumber
{
idphonenumber=[incMsgsender];
NSString*senderNumber=(NSString*)[phonenumbercanonicalFormat];
idincMsgPart=[[[[incMsgitems]objectAtIndex:0]retain]retain];
NSData*smsData=[[[incMsgPartdata]retain]retain];
//NSString*smsText=(NSString*)[[NSStringalloc]initWithData:smsDataencoding:NSASCIIStringEncoding];
NSString*smsText=[NSStringstringWithUTF8String:[smsDatabytes]];
NSLog(@"senderNumber=%@,text=%@",senderNumber,smsText);
}
}
}
//[poolrelease];
}
引用
注入監聽:
C++代碼
-(BOOL)application:(UIApplication*)applicationdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
self.window=[[[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]]autorelease];
//Overridepointforcustomizationafterapplicationlaunch.
self.window.backgroundColor=[UIColorwhiteColor];
[self.windowmakeKeyAndVisible];
idct=CTTelephonyCenterGetDefault();
CTTelephonyCenterAddObserver(ct,NULL,callback,NULL,NULL,CFNotificationSuspensionBehaviorDrop);
}