获取通话记录
小弟想获取手机某个时间以来所有的通话记录,比如获取自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);
}