0

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

问题线

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

1 回答 1

0

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

CFDateRef date = ABRecordCopyValue(lRef, kABPersonBirthdayProperty);
于 2011-08-23T05:02:59.047 回答