Is it possible to retrieve the create time of the iPhone contacts record?

前端 未结 2 892
北恋
北恋 2021-01-24 03:28

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.

2条回答
  •  再見小時候
    2021-01-24 03:30

    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
    

提交回复
热议问题