你好,歡迎來到IOS教程網

 Ios教程網 >> IOS使用技巧 >> IOS技巧綜合 >> Ios攔截手機短信程序

Ios攔截手機短信程序

編輯:IOS技巧綜合
[摘要]本文是對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);
}
  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved