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);
4

2 に答える 2

16

このコードを試してください:

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);
 }

それはあなたを助けます。

于 2012-05-01T10:33:59.413 に答える
4

CFDateRef以下を使用して、その人の誕生日のを取得します。

CFDateRef date = ABRecordCopyValue(person, kABPersonBirthdayProperty);
于 2012-04-17T12:40:40.497 に答える