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

  1. //extern id allIncomingMessages;
  2. //extern int incomingMessageCount;
  3. extern NSString* const kCTSMSMessageReceivedNotification;
  4. extern NSString* const kCTSMSMessageReplaceReceivedNotification;
  5. extern NSString* const kCTSIMSupportSIMStatusNotInserted;
  6. extern NSString* const kCTSIMSupportSIMStatusReady;
  7. //typedef struct _CTCall CTCall;
  8. extern NSString *CTCallCopyAddress(void*, CTCall *);
  9. void* CTSMSMessageSend(id server,id msg);
  10. typedef struct __CTSMSMessage CTSMSMessage;
  11. NSString *CTSMSMessageCopyAddress(void *, CTSMSMessage *);
  12. NSString *CTSMSMessageCopyText(void *, CTSMSMessage *);
  13. int CTSMSMessageGetRecordIdentifier(void * msg);
  14. NSString * CTSIMSupportGetSIMStatus();
  15. NSString * CTSIMSupportCopyMobileSubscriberIdentity();
  16. id  CTSMSMessageCreate(void* unknow/*always 0*/,NSString* number,NSString* text);
  17. void * CTSMSMessageCreateReply(void* unknow/*always 0*/,void * forwardTo,NSString* text);
  18. id CTTelephonyCenterGetDefault(void);
  19. void CTTelephonyCenterAddObserver(id,id,CFNotificationCallback,NSString*,void*,int);
  20. void CTTelephonyCenterRemoveObserver(id,id,NSString*,void*);
  21. int CTSMSMessageGetUnreadCount(void);
引用
回调函数:

  1. static void callback(CFNotificationCenterRef center,void *observer,CFStringRef name,const void *object, CFDictionaryRef userInfo){
  2. //    NSLog(@"%@",name);
  3. NSString *strNotficationName=(NSString*)name;
  4. if ([strNotficationName isEqualToString:@"kCTMessageReceivedNotification"]) {
  5. int a=0;
  6. }
  7. //    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  8. @synchronized(nil) {
  9. if (!userInfo) return;
  10. if ([[(NSDictionary *)userInfo allKeys]
  11. containsObject:@"kCTMessageIdKey"]) // SMS Message
  12. {
  13. NSDictionary *info = (NSDictionary *)userInfo;
  14. CFNumberRef msgID = (CFNumberRef)[info objectForKey:@"kCTMessageTypeKey"];
  15. int result;
  16. CFNumberGetValue((CFNumberRef)msgID, kCFNumberSInt32Type, &result);
  17. Class CTTelephonyCenter=NSClassFromString(@"CTTelephonyCenter");
  18. Class CTMessageCenter = NSClassFromString(@"CTMessageCenter");
  19. id mc = [CTMessageCenter sharedMessageCenter];
  20. int count=[mc incomingMessageCount];
  21. id mcarr=[mc allIncomingMessages];
  22. //        id incMsg =[mc incomingMessageWithId:result];
  23. //        if (count==0) {
  24. //            return;
  25. //        }
  26. id incMsg = [[mc allIncomingMessages] objectAtIndex:0];
  27. int msgType = (int)[incMsg messageType];
  28. if (msgType == 1) //experimentally detected number
  29. {
  30. id phonenumber = [incMsg sender];
  31. NSString *senderNumber = (NSString *)[phonenumber canonicalFormat];
  32. id incMsgPart = [[[[incMsg items] objectAtIndex:0] retain] retain];
  33. NSData *smsData = [[[incMsgPart data] retain] retain];
  34. //            NSString *smsText = (NSString*)[[NSString alloc] initWithData:smsData encoding:NSASCIIStringEncoding] ;
  35. NSString *smsText =    [NSString stringWithUTF8String:[smsData bytes]];
  36. NSLog(@"senderNumber = %@,text =%@",senderNumber,smsText);
  37. }
  38. }
  39. }
  40. //    [pool release];
  41. }
引用
注入监听:

  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. }

Ios拦截手机短信程序的更多相关文章

  1. Atitit. 破解  拦截 绕过 网站 手机 短信 验证码  方式 v2 attilax 总结

    Atitit. 破解  拦截 绕过 网站 手机 短信 验证码  方式 v2 attilax 总结 1. 验证码的前世今生11.1. 第一代验证码 图片验证码11.2. 第二代验证码  用户操作 ,比如 ...

  2. server宕机监控、检測、报警程序(139绑定手机短信报警)monitor_down.sh

    宕机监控报警程序 一.   需求来源 宕机对运维人员来说,最痛苦了.怎样检測一台server是否还在正常执行,假设该server宕机,怎样在第一时间监測到并通知一线运维人员进行维护,最大化降低损失. ...

  3. atitit.破解 拦截 绕过 网站 手机 短信 验证码 之自动获取手机短信方式 attilax 总结

    atitit.破解  拦截 绕过 网站 手机 短信 验证码 之自动获取手机短信方式 attilax 总结 1. 自动获取手机短信方式的原理 1 2. 调用api 1 3. ----核心代码 2 4.  ...

  4. SNF开发平台WinForm之十二-发送手机短信功能调用-金笛-SNF快速开发平台3.3-Spring.Net.Framework

    1.调用前组装参数 2.调用发送信息服务脚本   .调用前组装参数: BaseSendTaskEntity entity = new BaseSendTaskEntity(); entity.Mess ...

  5. 利用java实现的一个发送手机短信的小例子

    今天闲来无事,在微博上看到一个关于用java实现的一个发送手机短信的程序,看了看,写的不太相信,闲的没事,把他整理下来,以后可能用得着 JAVA发送手机短信,流传有几种方法:(1)使用webservi ...

  6. C#简单实现发送手机短信

    偶然想起,像编写一个从电脑向手机发送短信的程序,从网上查找到有三种方式:(1)使用webservice接口发送手机短信,这个可以使用sina提供的webservice进行发送,但是需要进行注册;(2) ...

  7. Android(java)学习笔记247:ContentProvider使用之利用ContentProvider备份和还原手机短信(掌握)

    1.通过阅读系统源码我们知道: 短信的内容提供者: content://sms/            系统短信的内容提供者的路径 2. 利用ContentProvider备份和还原手机短信: (1) ...

  8. JAVA发送手机短信

    <p><span>JAVA发送手机短信,流传有几种方法:(1)使用webservice接口发送手机短信,这个可以使用sina提供的webservice进行发送,但是需要进行注册 ...

  9. Android(java)学习笔记191:ContentProvider使用之利用ContentProvider备份和还原手机短信(掌握)

    1. 通过阅读系统源码我们知道: 短信的内容提供者: content://sms/            系统短信的内容提供者的路径 2. 利用ContentProvider备份和还原手机短信: (1 ...

随机推荐

  1. javascript中Math ceil(),floor(),round()三个函数的对比

    Math.ceil()执行的是向上舍入 Math.floor()执行向下舍入 Math.round()执行标准舍入 一下是一些补充: ceil():将小数部分一律向整数部分进位. 如: Math.ce ...

  2. 解决cell循环利用造成的重复勾选

    @interface ProfessionViewController (){ NSMutableArray *_professionArray;//cell模型数组 NSMutableArray * ...

  3. P2342 叠积木

    P2342 叠积木 17通过 66提交 题目提供者wwqk4444 标签树状数组线段树USACO 难度普及+/提高 提交该题 讨论 题解 记录 最新讨论 暂时没有讨论 题目背景 Cube Stacki ...

  4. CS对于dll文件的引用

    1.对于.net或者com型的组件,直接添加引用即可. 2.对于标准的dll文件,利用DLLImport这个函数即可,如果要使用函数的别名,那么应该加入EntryPoint. 示例:一般可以封装成一个 ...

  5. mvc的一些知识点

    MVC是微软2009对外公布的第一个开源的表示层框架,这是微软的第一个开源项目, MVC目的不是取代WebFrom开发,只是web开发的另外一种选择 1.MVC设计模式 M:Model 主要是存储或者 ...

  6. Part 13 Create a custom filter in AngularJS

    Custom filter in AngularJS 1. Is a function that returns a function 2. Use the filter function to cr ...

  7. js 用window.open(参数) 打开新窗口,在新窗口怎么获取传过来的参数

    unction openwin(taskno){window.open ('playIt.jsp?taskno='+taskno,'play','height=100,width=400,toolba ...

  8. xcode5下cocos2dx横竖屏设置

    我们在开发一款游戏之前一定会考虑的一件事就是,我们的游戏是支持横屏还是竖屏,又或者是横竖屏都支持.那么如何在xcode中对项目进行设置呢?下面我就在xcode5.1.1中利用cocos2dx2.2.3 ...

  9. c#高级编程第七版 学习笔记 第一章 .NET体系结构

    第一章      .NET体系结构 本章内容: 编译和运行面向.NET的代码 Microsoft中间语言(Microsoft Intermediate Language,MSIL或简称IL)的优点 值 ...

  10. 安装MySQL软件

    安装MySQL软件(绿色版) ① 解压软件包 ② 更改文件夹名称为mysql并复制到/usr/local文件夹下 ③ 使用cd指令进入/usr/local/mysql文件夹,使用ls –l查看 查看后 ...