本文介绍了在iOS 6中以编程方式获取通话记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用iOS 6开发一个iOS 应用程序。我需要以编程方式从iOS设备获取通话记录。我试过我的最好的,并得到一个解决方案,但它只适用于下面的iOS 5.
是否可以在iOS 5或iOS 6?
/ b> / private / var / wireless / 在我的ios5设备解决方案
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 = @< - ;打破;
case 5:flags = @ - >;打破;
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];
}
}
希望它有帮助!
I'm developing an iOS application using iOS 6. I need to get the call history from the iOS device programmatically. I've tried my best and got a solution but it only works in below iOS 5.Is it possible in above iOS 5 or in iOS 6?
解决方案
in my ios5 device, the call log location is
and here is my code to retrieve call log
- (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];
}
}
hope it helps!
这篇关于在iOS 6中以编程方式获取通话记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!