zoukankan      html  css  js  c++  java
  • [转载]短信与电话的拦截

    #import <UIKit/UIKit.h>
    #include <notify.h>
    #include <stdio.h>
    #include <stdarg.h>
    #include <string.h>
    typedef struct __CTSMSMessage CTSMSMessage;
    NSString *CTSMSMessageCopyAddress(void *, CTSMSMessage *);
    NSString *CTSMSMessageCopyText(void *, CTSMSMessage *);
    id CTTelephonyCenterGetDefault(void);
    void CTTelephonyCenterAddObserver(id,id,CFNotificationCallback,NSString*,void*,int);
    void dolog(id formatstring,...)
    {
        va_list arglist;
        if (formatstring)
        {
            va_start(arglist, formatstring);
            id outstring = [[NSString alloc] initWithFormat:formatstring arguments:arglist];
            printf("%s\n", [outstring UTF8String]);
            va_end(arglist);
        }
    }
    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 ([[(NSDictionary *)userInfo allKeys]
             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"];
            
            printf("  %s %d\n", [address cString], [lines count]);
            printf("  %s\n", [text cString]);
            fflush(stdout);
        }
        
        [pool release];
        
        return ;
    }
    static void signalHandler(int sigraised)
    {
        printf("\nInterrupted.\n");
        exit(0);
    }
    int main(int argc, char **argv)
    {
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        
        // Initialize listener by adding CT Center observer implicit
        id ct = CTTelephonyCenterGetDefault();
        CTTelephonyCenterAddObserver( ct, NULL, callback,NULL,NULL,
                                     CFNotificationSuspensionBehaviorHold);
        
        // Handle Interrupts
        sig_t oldHandler = signal(SIGINT, signalHandler);
        if (oldHandler == SIG_ERR)
        {
            printf("Could not establish new signal handler");
            exit(1);
        }
        
        // Run loop lets me catch notifications
        printf("Starting run loop and watching for notification.\n");
        CFRunLoopRun();
        
        // Shouldn't ever get here. Bzzzt
        printf("Unexpectedly back from CFRunLoopRun()!\n");
        [pool release];
    }
    

    转自:http://blog.csdn.net/laigb/article/details/6617264

  • 相关阅读:
    Adline网络的LMS算法与梯度下降
    Adaline网络识别印刷体数字0到9-java实现
    使用java API操作hdfs--拷贝部分文件到本地
    使用java API操作hdfs--拷贝部分文件到hdfs
    使用java API操作hdfs--读取hdfs文件并打印
    使用java API操作hdfs--通过filesystem API 来读取数据
    使用java API操作HDFS-相关环境的设置
    使用命令行的方式操作hdfs
    namenode和datanode 的namespaceID导致的问题
    The authenticity of host '172.16.33.53 (172.16.33.53)' can't be established的问题(日志六)
  • 原文地址:https://www.cnblogs.com/cklxmu/p/2398797.html
Copyright © 2011-2022 走看看