1

我正在使用 iOS 6 开发iOS应用程序。我需要以编程方式从 iOS 设备获取通话记录。我已经尽了最大努力并得到了解决方案,但它只适用于 iOS 5 以下。是否可以在 iOS 5 以上或 iOS 6 中使用?

4

2 回答 2

1

在我的 ios5 设备中,通话记录位置是

“/private/var/wireless/Library/CallHistory/call_history.db”

这是我检索通话记录的代码

- (void)getCallHistory
{  
    self.callHistories = [NSMutableArray array];

FMDatabase *db = [FMDatabase databaseWithPath:@"/private/var/wireless/Library/CallHistory/call_history.db"];

    NSLocale *usLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease];

if([db open]) {
    FMResultSet *rs = [db executeQuery:@"select address, date, flags, duration from call order by date"];
    while ([rs next]) {
        int dateInt = [rs intForColumn:@"date"];
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:dateInt];
        NSDateFormatter *df = [[NSDateFormatter alloc] init];
        [df setDateFormat:@"YYYY-MM-dd HH:mm"];
        NSString *dateString = [df stringFromDate:date];

        int flagsInt = [rs intForColumn:@"flags"];
        NSString *flags = @"?";
        switch (flagsInt) {
            case 4: flags = @"<-"; break;
            case 5: flags = @"->"; break;
            default: break;
        }

        int durationInt = [rs intForColumn:@"duration"];
        NSString *duration = [NSString stringWithFormat:@"%d:%02d", durationInt / 60, durationInt % 60];

        NSString *logLine = [NSString stringWithFormat:@"%@ %@ %@ (%@)", dateString, flags, [rs stringForColumn:@"address"], duration];
        [callHistories addObject:logLine];
    }
    [rs close];

    rs = [db executeQuery:@"select bytes_rcvd, bytes_sent from data where pdp_ip = 0"];
    while ([rs next]) {
        double bytes_sent = [rs doubleForColumn:@"bytes_sent"];
        double bytes_rcvd = [rs doubleForColumn:@"bytes_rcvd"];

        self.prettyBytesSent = [[NSNumber numberWithDouble:bytes_sent] prettyBytes];
        self.prettyBytesReceived = [[NSNumber numberWithDouble:bytes_rcvd] prettyBytes];
    }

    [rs close];

    [db close];
    }

}

希望能帮助到你!

于 2013-11-25T08:58:52.037 回答
0

你没有在 ios 5 call_history.db 中获取通话历史记录 bcoz 没有处于读取模式。所以你没有阅读这个 call_history.db 飞行。你只在越狱中阅读了这个数据库。

于 2012-12-14T13:18:13.293 回答