iphone - 在 iOS 6 中以编程方式获取通话记录

标签 iphone objective-c ios cocoa-touch

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

最佳答案

在我的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];
    }

}

希望对您有所帮助!

关于iphone - 在 iOS 6 中以编程方式获取通话记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13178382/

相关文章:

ios - 如何从嵌入在 View Controller 中的 TableView 中的 Collection View 传递数据并推送新的 View Controller ?

iphone - UIColor colorWithHue :saturation:brightness:alpha: always returning a red-tinted color 颜色

iphone - 如何在 OpenGL ES (iPhone) 中批量渲染 Sprite

iOS : Open my App Specific Location Settings

ios - 如何克服#import 循环?

objective-c - 如何在NSWindow上面画一个 "speech bubble"?

ios - 在iOS中,UIView动画和Core动画有什么区别?

ios - Titanium Appcelerator PUT方法不起作用

ios - 以编程方式将 UIImageView 添加到 UIScrollView

iphone - 将 GPS 坐标发送到服务器的最佳方式?