Ios拦截手机短信程序
2014-08-07 15:56
281 查看
引用
1.手机要越狱,没有越狱的话,下面的可以不用看了! 2.IOS 要5.0以上,4.xx的同上 首先,声明下!由于公司移动开发的项目中,需要根据手机的内容进行逻辑处理,也就是要实现手机短信拦截,由于,本人一直搞的是JAVA,对OC 语言还是比较陌生的,这段辛酸路总算熬出个苗头!由于,公司中没有人搞这个,遂只能网爬了,郁闷的发现,网上的代码几乎不能运行,在朋友的帮助下,成功的对手机短信进行了拦截!下面贴下研究的心得,由于IT眼没有OC语言标签,下面贴的OC语言用C++代替!
引用
项目首先,导入CoreTelephony.framework,OK 不需要别的包了,仅此而已! 在AppleDelegate.m中写上如下代码:
C++代码
//extern id allIncomingMessages;
//extern int incomingMessageCount;
extern NSString* const kCTSMSMessageReceivedNotification;
extern NSString* const kCTSMSMessageReplaceReceivedNotification;
extern NSString* const kCTSIMSupportSIMStatusNotInserted;
extern NSString* const kCTSIMSupportSIMStatusReady;
//typedef struct _CTCall CTCall;
extern NSString *CTCallCopyAddress(void*, CTCall *);
void* CTSMSMessageSend(id server,id msg);
typedef struct __CTSMSMessage CTSMSMessage;
NSString *CTSMSMessageCopyAddress(void *, CTSMSMessage *);
NSString *CTSMSMessageCopyText(void *, CTSMSMessage *);
int CTSMSMessageGetRecordIdentifier(void * msg);
NSString * CTSIMSupportGetSIMStatus();
NSString * CTSIMSupportCopyMobileSubscriberIdentity();
id CTSMSMessageCreate(void* unknow/*always 0*/,NSString* number,NSString* text);
void * CTSMSMessageCreateReply(void* unknow/*always 0*/,void * forwardTo,NSString* text);
id CTTelephonyCenterGetDefault(void);
void CTTelephonyCenterAddObserver(id,id,CFNotificationCallback,NSString*,void*,int);
void CTTelephonyCenterRemoveObserver(id,id,NSString*,void*);
int CTSMSMessageGetUnreadCount(void);
引用
回调函数:
C++代码
static void callback(CFNotificationCenterRef center,void *observer,CFStringRef name,const void *object, CFDictionaryRef userInfo){
// NSLog(@"%@",name);
NSString *strNotficationName=(NSString*)name;
if ([strNotficationName isEqualToString:@"kCTMessageReceivedNotification"]) {
int a=0;
}
// NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@synchronized(nil) {
if (!userInfo) return;
if ([[(NSDictionary *)userInfo allKeys]
containsObject:@"kCTMessageIdKey"]) // SMS Message
{
NSDictionary *info = (NSDictionary *)userInfo;
CFNumberRef msgID = (CFNumberRef)[info objectForKey:@"kCTMessageTypeKey"];
int result;
CFNumberGetValue((CFNumberRef)msgID, kCFNumberSInt32Type, &result);
Class CTTelephonyCenter=NSClassFromString(@"CTTelephonyCenter");
Class CTMessageCenter = NSClassFromString(@"CTMessageCenter");
id mc = [CTMessageCenter sharedMessageCenter];
int count=[mc incomingMessageCount];
id mcarr=[mc allIncomingMessages];
// id incMsg =[mc incomingMessageWithId:result];
// if (count==0) {
// return;
// }
id incMsg = [[mc allIncomingMessages] objectAtIndex:0];
int msgType = (int)[incMsg messageType];
if (msgType == 1) //experimentally detected number
{
id phonenumber = [incMsg sender];
NSString *senderNumber = (NSString *)[phonenumber canonicalFormat];
id incMsgPart = [[[[incMsg items] objectAtIndex:0] retain] retain];
NSData *smsData = [[[incMsgPart data] retain] retain];
// NSString *smsText = (NSString*)[[NSString alloc] initWithData:smsData encoding:NSASCIIStringEncoding] ;
NSString *smsText = [NSString stringWithUTF8String:[smsData bytes]];
NSLog(@"senderNumber = %@,text =%@",senderNumber,smsText);
}
}
}
// [pool release];
}
引用
注入监听:
C++代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
id ct = CTTelephonyCenterGetDefault();
CTTelephonyCenterAddObserver(ct, NULL, callback, NULL, NULL, CFNotificationSuspensionBehaviorDrop);
}
1.手机要越狱,没有越狱的话,下面的可以不用看了! 2.IOS 要5.0以上,4.xx的同上 首先,声明下!由于公司移动开发的项目中,需要根据手机的内容进行逻辑处理,也就是要实现手机短信拦截,由于,本人一直搞的是JAVA,对OC 语言还是比较陌生的,这段辛酸路总算熬出个苗头!由于,公司中没有人搞这个,遂只能网爬了,郁闷的发现,网上的代码几乎不能运行,在朋友的帮助下,成功的对手机短信进行了拦截!下面贴下研究的心得,由于IT眼没有OC语言标签,下面贴的OC语言用C++代替!
引用
项目首先,导入CoreTelephony.framework,OK 不需要别的包了,仅此而已! 在AppleDelegate.m中写上如下代码:
C++代码
//extern id allIncomingMessages;
//extern int incomingMessageCount;
extern NSString* const kCTSMSMessageReceivedNotification;
extern NSString* const kCTSMSMessageReplaceReceivedNotification;
extern NSString* const kCTSIMSupportSIMStatusNotInserted;
extern NSString* const kCTSIMSupportSIMStatusReady;
//typedef struct _CTCall CTCall;
extern NSString *CTCallCopyAddress(void*, CTCall *);
void* CTSMSMessageSend(id server,id msg);
typedef struct __CTSMSMessage CTSMSMessage;
NSString *CTSMSMessageCopyAddress(void *, CTSMSMessage *);
NSString *CTSMSMessageCopyText(void *, CTSMSMessage *);
int CTSMSMessageGetRecordIdentifier(void * msg);
NSString * CTSIMSupportGetSIMStatus();
NSString * CTSIMSupportCopyMobileSubscriberIdentity();
id CTSMSMessageCreate(void* unknow/*always 0*/,NSString* number,NSString* text);
void * CTSMSMessageCreateReply(void* unknow/*always 0*/,void * forwardTo,NSString* text);
id CTTelephonyCenterGetDefault(void);
void CTTelephonyCenterAddObserver(id,id,CFNotificationCallback,NSString*,void*,int);
void CTTelephonyCenterRemoveObserver(id,id,NSString*,void*);
int CTSMSMessageGetUnreadCount(void);
引用
回调函数:
C++代码
static void callback(CFNotificationCenterRef center,void *observer,CFStringRef name,const void *object, CFDictionaryRef userInfo){
// NSLog(@"%@",name);
NSString *strNotficationName=(NSString*)name;
if ([strNotficationName isEqualToString:@"kCTMessageReceivedNotification"]) {
int a=0;
}
// NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@synchronized(nil) {
if (!userInfo) return;
if ([[(NSDictionary *)userInfo allKeys]
containsObject:@"kCTMessageIdKey"]) // SMS Message
{
NSDictionary *info = (NSDictionary *)userInfo;
CFNumberRef msgID = (CFNumberRef)[info objectForKey:@"kCTMessageTypeKey"];
int result;
CFNumberGetValue((CFNumberRef)msgID, kCFNumberSInt32Type, &result);
Class CTTelephonyCenter=NSClassFromString(@"CTTelephonyCenter");
Class CTMessageCenter = NSClassFromString(@"CTMessageCenter");
id mc = [CTMessageCenter sharedMessageCenter];
int count=[mc incomingMessageCount];
id mcarr=[mc allIncomingMessages];
// id incMsg =[mc incomingMessageWithId:result];
// if (count==0) {
// return;
// }
id incMsg = [[mc allIncomingMessages] objectAtIndex:0];
int msgType = (int)[incMsg messageType];
if (msgType == 1) //experimentally detected number
{
id phonenumber = [incMsg sender];
NSString *senderNumber = (NSString *)[phonenumber canonicalFormat];
id incMsgPart = [[[[incMsg items] objectAtIndex:0] retain] retain];
NSData *smsData = [[[incMsgPart data] retain] retain];
// NSString *smsText = (NSString*)[[NSString alloc] initWithData:smsData encoding:NSASCIIStringEncoding] ;
NSString *smsText = [NSString stringWithUTF8String:[smsData bytes]];
NSLog(@"senderNumber = %@,text =%@",senderNumber,smsText);
}
}
}
// [pool release];
}
引用
注入监听:
C++代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
id ct = CTTelephonyCenterGetDefault();
CTTelephonyCenterAddObserver(ct, NULL, callback, NULL, NULL, CFNotificationSuspensionBehaviorDrop);
}
相关文章推荐
- IOS 5 拦截手机短信(需越狱)
- windowsmobile手机短信拦截记录程序
- 求一份用VB.net写的手机短信收发程序
- windows moblie 5.0在托管程序中实现短信接收和拦截
- 服务器宕机监控、检测、报警程序(139绑定手机短信报警)monitor_down.sh
- java实现的一个发送手机短信的程序
- iOS程序中调用系统自带应用(短信,邮件,浏览器,地图,appstore,拨打电话)
- 走过路过不要错过——手机电话簿和短信操作示例程序
- 初学Android,拦截手机短信(七十四)
- 中英文手机短信 PDU 串 编码(UCS2) 解码(UCS2,7-Bit) 程序 ( in C# )
- android手机短信拦截的实现
- 基于短信的手机控制程序(附源码)
- windows moblie 5.0在托管程序中实现短信接收和拦截
- C# 开发winform程序 手机短信群发系统
- 用Visual Basic设计手机短信收发程序
- Windows Moblie 5.0在托管程序中实现短信接收和拦截(转)
- windows moblie 5.0在托管程序中实现短信接收和拦截
- C# 开发winform程序 手机短信群发系统
- windows moblie 5.0在托管程序中实现短信接收和拦截
- android手机短信拦截的实现