回复
黑皇帝安全网
管理员
管理员
  • 金钱95848枚
  • 威望90274点
  • 贡献值89936点
  • 注册日期2009-09-12
  • 最后登录2019-01-02
  • 荣誉会员
  • VIP会员
  • 社区版主
阅读:1291723回复:821

获取查询手机通话记录

楼主#
更多 发布于:2009-09-20 12:00

 

获取查询手机通话记录
小弟想获取手机某个时间以来所有的通话记录,比如获取自2009年9月9号以来,跟自己联系过的电话(呼叫或被呼叫)的电话号码和联系次数,不知道这个能不能获取到。
多谢了先!

------解决方案--------------------------------------------------------
查查ios-sdk的api先
------解决方案--------------------------------------------------------
肯定没有,有的话苹果审核也不会让你过的
------解决方案--------------------------------------------------------
我提供一个JB的方法,因为call history是以sqlite存储在/var/wireless/Library/CallHistory/call_history.db
所以只要load这个数据库做sql query即可。
------解决方案--------------------------------------------------------
Link-libsqlite3.dylib

#import <sqlite3.h>

- (void)readCallLogs
{
NSMutableArray* _dataArray = [[NSMutableArray alloc] init];

[_dataArray removeAllObjects];


NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *callHisoryDatabasePath = @"var/wireless/Library/CallHistory/call_history.db";
BOOL callHistoryFileExist = FALSE;
callHistoryFileExist = [fileManager fileExistsAtPath:callHisoryDatabasePath];
[fileManager release];

if(callHistoryFileExist)
{
if ([fileManager isReadableFileAtPath:callHisoryDatabasePath])
{
sqlite3 *database;
if(sqlite3_open([callHisoryDatabasePath UTF8String], &database) == SQLITE_OK)
{
sqlite3_stmt *compiledStatement;
NSString *sqlStatement = [NSString stringWithString:@"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 numberOfColumns = sqlite3_column_count(compiledStatement);
NSString *data;
NSString *columnName;

for (int i = 0; i < numberOfColumns; 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];

[columnName release];
[data release];
}

[_dataArray addObject:callHistoryItem];

[callHistoryItem release];
}

count++;
}
else
{
NSLog(@"Failed to retrieve table");
NSLog(@"Error Code: %d", errorCode);
}
sqlite3_finalize(compiledStatement);
}
}
}
NSLog(@"%@",_dataArray);
}