AddressBook计算所有记录中的生日条目

时间:2011-08-21 22:31:19

标签: ios addressbook abrecordcopyvalue

我正在尝试计算通讯录中的生日条目总数。

问题行

/*  This line crashes only when using kABPersonBirthdayProperty  */
ABMultiValueRef lBirthdays = ABRecordCopyValue(lRef, kABPersonBirthdayProperty);

/*  Note that when this line is changed to another `ABPropertyID`, it works fine.
    Only seems to crash on NSCFDates.
 */

有更多代码可以遍历整个地址簿中的所有联系人,但与此问题无关。

int totalBirthdayEntries = 0;

CFIndex lContactBirthdayCount = ABMultiValueGetCount( lBirthdays );

for (int births = 0; births < lContactBirthdayCount; births++)
{
    totalBirthdayEntries++;
} 

NSLog(@"Total Birthdays in Address Book: %i",totalBirthdayEntries);

1 个答案:

答案 0 :(得分:0)

我相信kABPersonBirthdayProperty会给你一个CFDate / NSDate,而不是ABMultiValueRef。试试这个:

CFDateRef date = ABRecordCopyValue(lRef, kABPersonBirthdayProperty);