How to get birthday list contacts from iphone
Asked Answered
B

2

6
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);
Burkett answered 17/4, 2012 at 12:11 Comment(1)
Could please explain what is the problem?Polygenesis
H
16

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.

Hess answered 1/5, 2012 at 10:33 Comment(0)
D
4

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

CFDateRef date = ABRecordCopyValue(person, kABPersonBirthdayProperty);
Dither answered 17/4, 2012 at 12:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.