大学IT网 - 最懂大学生的IT学习网站! QQ资料交流群:367606806
当前位置:大学IT网 > IOS技巧 > Ios拦截手机短信程序

Ios拦截手机短信程序

关键词:拦截手机短信Ios  阅读(1074) 赞(10)

[摘要]本文是对Ios拦截手机短信程序的讲解,对学习IOS苹果软件开发有所帮助,与大家分享。
引用
1.手机要越狱,没有越狱的话,下面的可以不用看了! 2.IOS 要5.0以上,4.xx的同上 首先,声明下!由于公司移动开发的项目中,需要根据手机的内容进行逻辑处理,也就是要实现手机短信拦截,由于,本人一直搞的是JAVA,对OC 语言还是比较陌生的,这段辛酸路总算熬出个苗头!由于,公司中没有人搞这个,遂只能网爬了,郁闷的发现,网上的代码几乎不能运行,在朋友的帮助下,成功的对手机短信进行了拦截!下面贴下研究的心得,由于IT眼没有OC语言标签,下面贴的OC语言用C++代替!
引用
项目首先,导入CoreTelephony.framework,OK 不需要别的包了,仅此而已! 在AppleDelegate.m中写上如下代码:

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);
}


相关评论