Rock
Rock

Reputation: 1510

How to get birthday list contacts from iphone

ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef nameArray = ABAddressBookCopyArrayOfAllPeople (addressBook);

m_SourceContactsUserArray = [[NSMutableArray alloc] init];
for (int i = 0; i<CFArrayGetCount(nameArray); i++) {
    ABRecordRef person = CFArrayGetValueAtIndex(nameArray, i);
    NSString *personName = (NSString*)ABRecordCopyValue(person,kABPersonFirstNameProperty);
    [m_SourceContactsUserArray addObject:personName];
}
CFRelease(addressBook);
CFRelease(nameArray);

Upvotes: 6

Views: 2111

Answers (2)

Dhaval Bhadania
Dhaval Bhadania

Reputation: 3089

Try this code:

ABAddressBookRef myAddressBook = ABAddressBookCreate();
NSArray *allPeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(myAddressBook);

for (id record in allPeople) {
    NSMutableDictionary *newRecord = [[NSMutableDictionary alloc] init];
    CFTypeRef bDayProperty = ABRecordCopyValue((ABRecordRef)record, kABPersonBirthdayProperty);

    if (ABRecordCopyValue((ABRecordRef)record, kABPersonBirthdayProperty)) 
           {
        NSDate *date=(NSDate*)bDayProperty;
        [newRecord setObject:date forKey:@"birthDate"];
        date=nil;
        [date release]; 
    }
   CFRelease(myAddressBook);
 }

it will help you.

Upvotes: 16

jrtc27
jrtc27

Reputation: 8536

Use the following to obtain a CFDateRef for the person's birthday:

CFDateRef date = ABRecordCopyValue(person, kABPersonBirthdayProperty);

Upvotes: 4

Related Questions