2012-04-17 40 views
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); 
+3

請說明是什麼問題? – 2012-04-17 12:18:11

回答

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

它會幫助你。

4

使用得到的生日列表中的聯繫人下面以獲得人的生日CFDateRef

CFDateRef date = ABRecordCopyValue(person, kABPersonBirthdayProperty);