0 0

IOS 短信截取 监听到了事件缺不能往下执行。。。0

引用

大家好,小生刚到公司就顶起了iPhone模块的模块。犹豫自感闭门造车,所以,学到的都是些很肤浅的东西。现在公司项目要求截取手机短信内容及手机号码。google了下,终于可以运行了,但是,缺卡在了代码关键处,往下不能执行了,所以,谢谢给位帮忙看下,不甚感激!


引用
用到的头文件

#ifndef Player_MessageHFile_h
#define Player_MessageHFile_h

extern NSString* const kCTSMSMessageReceivedNotification;
extern NSString* const kCTSMSMessageReplaceReceivedNotification;
extern NSString* const kCTSIMSupportSIMStatusNotInserted;
extern NSString* const kCTSIMSupportSIMStatusReady;

id CTTelephonyCenterGetDefault(void);
void CTTelephonyCenterAddObserver(id,id,CFNotificationCallback,NSString*,void*,int);
void CTTelephonyCenterRemoveObserver(id,id,NSString*,void*);
int CTSMSMessageGetUnreadCount(void);

int CTSMSMessageGetRecordIdentifier(void * msg);
NSString * CTSIMSupportGetSIMStatus();   //获取sim卡状态,kCTSIMSupportSIMStatusNotInserted表示没有sim卡
NSString * CTSIMSupportCopyMobileSubscriberIdentity();  //获取imsi号码,泪牛满面啊,我原来都是用AT+CCID来获取的iccid识别用户

id  CTSMSMessageCreate(void* unknow/*always 0*/,NSString* number,NSString* text);
void * CTSMSMessageCreateReply(void* unknow/*always 0*/,void * forwardTo,NSString* text);

void* CTSMSMessageSend(id server,id msg);

NSString *CTSMSMessageCopyAddress(void *, void *);
NSString *CTSMSMessageCopyText(void *, void *);

#endif


引用

AppDelegate.m 中进行引用:
#import "MessageHFile.h"



引用

回调函数:
static void callback(CFNotificationCenterRef center,    
                     void *observer, CFStringRef name,    
                     const void *object, CFDictionaryRef userInfo)    
{    
    
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];    
    // printf("NOTIFICATION: %s\n", [name UTF8String]);    
    if (!userInfo) return;    
    
    NSDictionary *info = (NSDictionary*)userInfo;    
    int dcount = CFDictionaryGetCount(userInfo);    
    id keys = [(NSDictionary*)userInfo allKeys];    
    int i;    
    for (i = 0; i < dcount; i++)    
    {    
        id key = [keys objectAtIndex:i];    
        dolog(@"  %@: %@", key, [info objectForKey:key]);    
    }        
    
    if ([keys containsObject:@"kCTSMSMessage"]) // SMS Message    
    {    
        CTSMSMessage *message = (CTSMSMessage *)    
        [(NSDictionary *)userInfo objectForKey:@"kCTSMSMessage"];    
        NSString *address = CTSMSMessageCopyAddress(NULL, message);    
        NSString *text = CTSMSMessageCopyText(NULL, message);    
        NSArray *lines = [text componentsSeparatedByString:@"\n"];    
        
        NSLog(@"address = %@,text =%@,linesCount =%d",address,text,[lines count]);
        
        fflush(stdout);    
    }    
    
    [pool release];    
    
    return ;    
}   



引用

注入监听:
    //注入监听
    CTTelephonyCenterAddObserver(CTTelephonyCenterGetDefault(),NULL, &callback, NULL, NULL, CFNotificationSuspensionBehaviorHold);



[b]
引用

我现在的问题是:回调函数执行到
 if ([keys containsObject:@"kCTSMSMessage"]) // SMS Message  

不执行了!我估想是根本没有kCTSMSMessage 这样的短信类别。求给位大大帮忙看下啊,项目没有任何黄点和红点,就是不能运行,再帖上附件

[/b]
2012年5月29日 16:00
目前还没有答案

相关推荐

Global site tag (gtag.js) - Google Analytics