获取iPhone通话记录(需越狱)

首先导入库框架#import <sqlite3.h>

越狱后的手机的数据库文件可以自由访问,通话记录通常保存在call_History.db这个文件中.只要读取这个文件,我们就能知道目前手机的通话记录了

下面这段代码检测手机是否能读取到Call_History.db

//检测手机能否读取到Call_History.db
- (void)initData{
    NSFileManager *fileManager=[NSFileManager defaultManager];
    NSDirectoryEnumerator *dirum=[[NSFileManager defaultManager]enumeratorAtPath:@"/private/"];
    NSString *nextItem=[NSString string];
    while ((nextItem=[dirum nextObject])) {
        if ([[nextItem pathExtension] isEqualToString:@"db"]||
            [[nextItem pathExtension]isEqualToString:@"sqlitedb"]) {
            if ([fileManager isReadableFileAtPath:nextItem]) {
                NSLog(@"%@",nextItem);
            }
        }
    }
}

//读取数据库中的内容   具体怎样显示自己定制
- (void)readCallLogs{
    if (self.dataArray==nil) {
        self.dataArray=[[NSMutableArray alloc]init];
    }
    [self.dataArray removeAllObjects];
    NSFileManager *fileManager=[NSFileManager defaultManager];
    NSString *callHistoryDatabasePath=@"var/wireless/Library/CallHistory/call_history.db";
    BOOL callHistoryFileExist=FALSE;
    callHistoryFileExist=[fileManager fileExistsAtPath:callHistoryDatabasePath];
    
    if (callHistoryFileExist) {
        if ([fileManager isReadableFileAtPath:callHistoryDatabasePath]) {
            sqlite3 *database;
            if (sqlite3_open([callHistoryDatabasePath UTF8String], &database)==SQLITE_OK) {
                sqlite3_stmt *compiledStatement;
                NSString *sqlStatement=@"SELECT * FROM call";
                //
                int errorCode=sqlite3_prepare_v2(database, [sqlStatement UTF8String], -1, &compiledStatement, NULL);
                if (errorCode==SQLITE_OK) {
                    int count=1;
                    while (sqlite3_step(compiledStatement)==SQLITE_ROW) {
                        //Read the data from the result row
                        NSMutableDictionary *callHistoryItem=[[NSMutableDictionary alloc]init];
                        int numOfColumns=sqlite3_column_count(compiledStatement);
                        NSString *data;
                        NSString *columnName;
                        for (int i= 0; i<numOfColumns; i++) {
                            columnName=[[NSString alloc]initWithUTF8String:(char *)sqlite3_column_name(compiledStatement, i)];
                            data=[[NSString alloc]initWithUTF8String:(char *)sqlite3_column_text(compiledStatement, i)];
                        }
                        //放入字典
                        [callHistoryItem setObject:data forKey:columnName];
                        [self.dataArray addObject:callHistoryItem];
                        count++;
                    }
                   
                }else{
                
                    NSLog(@"Failed to retrieve table");
                    NSLog(@"Error Code :%d",errorCode);
                }
                sqlite3_finalize(compiledStatement);
                
            }
        }
    }
    NSLog(@"%@",self.dataArray);
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值