簡體   English   中英

在iOS 6中以編程方式獲取通話記錄

[英]Get call history programmatically in iOS 6

我正在使用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];
    }

}

希望能幫助到你!

您未在ios 5中獲得呼叫歷史記錄bcoz call_history.db處於非讀取模式。因此,您未讀取此call_history.db文件。您僅在越獄時讀取了此數據庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM