zoukankan      html  css  js  c++  java
  • Ios拦截手机短信程序

    引用
    1.手机要越狱,没有越狱的话,下面的可以不用看了!  2.IOS 要5.0以上,4.xx的同上  首先,声明下!由于公司移动开发的项目中,需要根据手机的内容进行逻辑处理,也就是要实现手机短信拦截,由于,本人一直搞的是JAVA,对OC 语言还是比较陌生的,这段辛酸路总算熬出个苗头!由于,公司中没有人搞这个,遂只能网爬了,郁闷的发现,网上的代码几乎不能运行,在朋友的帮助下,成功的对手机短信进行了拦截!下面贴下研究的心得,由于IT眼没有OC语言标签,下面贴的OC语言用C++代替! 
    引用
    项目首先,导入CoreTelephony.framework,OK 不需要别的包了,仅此而已!  在AppleDelegate.m中写上如下代码: 
    C++代码  收藏代码
    1. //extern id allIncomingMessages;  
    2. //extern int incomingMessageCount;  
    3.   
    4. extern NSString* const kCTSMSMessageReceivedNotification;  
    5. extern NSString* const kCTSMSMessageReplaceReceivedNotification;  
    6. extern NSString* const kCTSIMSupportSIMStatusNotInserted;  
    7. extern NSString* const kCTSIMSupportSIMStatusReady;  
    8.   
    9.   
    10. //typedef struct _CTCall CTCall;  
    11. extern NSString *CTCallCopyAddress(void*, CTCall *);   
    12. void* CTSMSMessageSend(id server,id msg);  
    13. typedef struct __CTSMSMessage CTSMSMessage;  
    14. NSString *CTSMSMessageCopyAddress(void *, CTSMSMessage *);  
    15. NSString *CTSMSMessageCopyText(void *, CTSMSMessage *);  
    16.   
    17. int CTSMSMessageGetRecordIdentifier(void * msg);  
    18. NSString * CTSIMSupportGetSIMStatus();  
    19. NSString * CTSIMSupportCopyMobileSubscriberIdentity();  
    20. id  CTSMSMessageCreate(void* unknow/*always 0*/,NSString* number,NSString* text);  
    21. void * CTSMSMessageCreateReply(void* unknow/*always 0*/,void * forwardTo,NSString* text);  
    22.   
    23. id CTTelephonyCenterGetDefault(void);  
    24. void CTTelephonyCenterAddObserver(id,id,CFNotificationCallback,NSString*,void*,int);  
    25. void CTTelephonyCenterRemoveObserver(id,id,NSString*,void*);  
    26. int CTSMSMessageGetUnreadCount(void);   
    引用
    回调函数: 
    C++代码  收藏代码
    1. static void callback(CFNotificationCenterRef center,void *observer,CFStringRef name,const void *object, CFDictionaryRef userInfo){  
    2.       
    3. //    NSLog(@"%@",name);  
    4.      
    5.     NSString *strNotficationName=(NSString*)name;  
    6.       
    7.       
    8.     if ([strNotficationName isEqualToString:@"kCTMessageReceivedNotification"]) {  
    9.         int a=0;      
    10.     }  
    11.       
    12. //    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];  
    13.      @synchronized(nil) {  
    14.         if (!userInfo) return;  
    15.         if ([[(NSDictionary *)userInfo allKeys]  
    16.              containsObject:@"kCTMessageIdKey"]) // SMS Message  
    17.         {  
    18.   
    19.               
    20.             NSDictionary *info = (NSDictionary *)userInfo;  
    21.             CFNumberRef msgID = (CFNumberRef)[info objectForKey:@"kCTMessageTypeKey"];  
    22.             int result;  
    23.             CFNumberGetValue((CFNumberRef)msgID, kCFNumberSInt32Type, &result);   
    24.             Class CTTelephonyCenter=NSClassFromString(@"CTTelephonyCenter");  
    25.               
    26.             Class CTMessageCenter = NSClassFromString(@"CTMessageCenter");  
    27.             id mc = [CTMessageCenter sharedMessageCenter];  
    28.             int count=[mc incomingMessageCount];  
    29.             id mcarr=[mc allIncomingMessages];  
    30.     //        id incMsg =[mc incomingMessageWithId:result];  
    31.     //        if (count==0) {  
    32.     //            return;  
    33.     //        }  
    34.             id incMsg = [[mc allIncomingMessages] objectAtIndex:0];  
    35.               
    36.             int msgType = (int)[incMsg messageType];  
    37.               
    38.             if (msgType == 1) //experimentally detected number  
    39.             {  
    40.                 id phonenumber = [incMsg sender];  
    41.                   
    42.                 NSString *senderNumber = (NSString *)[phonenumber canonicalFormat];  
    43.             id incMsgPart = [[[[incMsg items] objectAtIndex:0] retain] retain];  
    44.             NSData *smsData = [[[incMsgPart data] retain] retain];  
    45. //            NSString *smsText = (NSString*)[[NSString alloc] initWithData:smsData encoding:NSASCIIStringEncoding] ;  
    46.               NSString *smsText =    [NSString stringWithUTF8String:[smsData bytes]];  
    47.   
    48.                 NSLog(@"senderNumber = %@,text =%@",senderNumber,smsText);  
    49.             }  
    50.           
    51.         }  
    52.           
    53.     }  
    54.   
    55. //    [pool release];  
    56.       
    57.       
    58.   
    59. }  
    引用
    注入监听: 
    C++代码  收藏代码
    1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
    2. {  
    3.     self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];  
    4.     // Override point for customization after application launch.  
    5.     self.window.backgroundColor = [UIColor whiteColor];  
    6.     [self.window makeKeyAndVisible];  
    7.     id ct = CTTelephonyCenterGetDefault();   
    8.     CTTelephonyCenterAddObserver(ct, NULL, callback, NULL, NULL, CFNotificationSuspensionBehaviorDrop);  
    9. }  
  • 相关阅读:
    Oracle 查看表空间的使用情况SQL语句
    汇总查询
    conky配置2
    数据库更新
    weka简介和回归转自chinakdd
    子查询
    ubuntu常用命令
    查询
    数据库中的连接
    测试用的数据库表及其数据
  • 原文地址:https://www.cnblogs.com/lovewx/p/3897378.html
Copyright © 2011-2022 走看看