本文介绍了是否可以检索iPhone联系人记录的创建时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一个关于iPhone的问题。是否可以从每条记录的iPhone联系人中检索创建时间?谢谢。

I want to ask a question about iPhone. Is it possible to retrieve the creation time from the iPhone contacts of each record? Thank you.

推荐答案

是的。你想要 kABPersonCreationDateProperty 。请参阅。

Yes. You want the kABPersonCreationDateProperty. See the reference.

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];    

ABAddressBookRef addressBook = ABAddressBookCreate();

NSArray* allPeople = (NSArray*) ABAddressBookCopyArrayOfAllPeople( addressBook );
for( id aPerson in allPeople ) {
    NSString* firstName = (NSString*) ABRecordCopyValue( aPerson, kABPersonFirstNameProperty );
    NSString* lastName = (NSString* ) ABRecordCopyValue( aPerson, kABPersonLastNameProperty );
    NSDate* createDate = (NSDate*) ABRecordCopyValue( aPerson, kABPersonCreationDateProperty );
    NSString* formattedDate = [dateFormatter stringFromDate:createDate];

    NSLog( @"%@ %@ created %@", firstName, lastName, formattedDate );

    [firstName release];
    [lastName release];
    [createDate release];
}

[allPeople release];
[dateFormatter release];
CFRelease(addressBook);

哪些输出......

Which outputs...

AddressBookTest[6202:207] Zacharias Pasternack created 9/24/10 9:03:34 AM PDT
AddressBookTest[6202:207] Some Other Guy created 9/24/10 9:07:18 AM PDT

这篇关于是否可以检索iPhone联系人记录的创建时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 18:01