引用
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. codeforces 676C C. Vasya and String(二分)

    题目链接: C. Vasya and String time limit per test 1 second memory limit per test 256 megabytes input sta ...

  2. Meta也很强

    <!--http-equiv 必要属性--> <meta http-equiv="Content-Type" content="text/html; c ...

  3. php中一串数子的转化

    echo "<meta charset=utf-8>"; echo "笔试题测试"; $str = "123456780"; $ ...

  4. 网络安全-PGP实现电子邮件加密

    PGP机制

  5. Windows Kernel Way 1:Windows内核调试技术

    掌握Windows内核调试技术是学习与研究Windows内核的基础,调试Windows内核的方式大致分为两种: (1)通过Windbg工具在Windows系统运行之初连接到Windows内核,连接成功 ...

  6. cocos2d-x一些核心概念截杀

    Cocos2d-x中有很多概念,这些概念很多来源于动画.动漫和电影等行业,例如:导演.场景和层等概念,当然也有些有传统的游戏的概念.Cocos2d-x中核心概念:导演, 场景,层,节点,精灵,菜单动作 ...

  7. dateset是不是在缓存中

    C#开发erp系统的时候有一个多表数据的查询展示到页面,采用了存储过程的方式,但是存储过程中没有加入分页(菜比).刚开始测试数据几百条没有问题,当数据量提升至十万级后页面加载速度就很卡了,一般是使用分 ...

  8. in C#,编译型常量(const)和运行时常量(readonly)

    readonly 关键字与 const 关键字不同. const 字段只能在该字段的声明中初始化. readonly 字段可以在声明或构造函数中初始化. 因此,根据所使用的构造函数, readonly ...

  9. spring注解中使用properties文件

    一.只读取单个 properties 文件 1.在 spring 的配置文件中,加入 引入命名空间: xmlns:util="http://www.springframework.org/s ...

  10. Ajax 技术二

    一.Ajax与XML案例 例:使用Ajax+XML读取数据表中的分类信息并放入下拉选框中 demo01.php 运行结果: 二.Ajax中的JSON 在Javascript中,可以通过两种方式(XML ...