我提供一个JB的方法,因为call history是以sqlite存储在/var/wireless/Library/CallHistory/call_history.db
所以只要load这个数据库做sql query即可。

解决方案 »

  1.   

    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);  
      

  2.   

    给你一个JB的方式
    ios将通话记录信息存在/var/wireless/Library/CallHistory/call_history.db
    sqlite格式,直接sql query就能满足你的要求