In Contacts I have set up a Date field with a custom label (when editing a contact you select Add Field-> Date -> Anniversary -> Add Custom Label).
This is stored in the ABMultiValue property of ID 'kABPersonDateProperty' with a label of (for example) 'Next Appointment'.
The ABMultiValue API has functions to tell me the label name at an index, read the value at an index and convert between ID/Index.
Please forgive me 开发者_Go百科if I am being thick here but is the quickest way to get the date of the 'Next Appointment' to iterate the Multivalue field looking for the index of a matching label then copy the value of the property at that index? From what I can tell, the index will vary from record to record.
I realise there is a function to get an index from a property ID, but that means that at some point earlier I will have to have discovered the propertyID by going through all the records trying to find one with the 'Next Appointment' field in it to get its propertyid.
I want to view the date in a tableview and sort on it so I need to get the value as efficiently as possible. Has anyone got a method of doing this quickly, preferably with example code or a link for further info?
The approach you describe is correct. You will want to do something similar to Apple's sample code for multivalue properties from the Address Book Programming Guide for iPhone OS:
CFStringRef phoneNumber, phoneNumberLabel;
multi = ABRecordCopyValue(aRecord, kABPersonPhoneProperty);
for (CFIndex i = 0; i < ABMultiValueGetCount(multi); i++) {
phoneNumberLabel = ABMultiValueCopyLabelAtIndex(multi, i);
phoneNumber = ABMultiValueCopyValueAtIndex(multi, i);
/* ... do something with phoneNumberLabel and phoneNumber ... */
CFRelease(phoneNumberLabel);
CFRelease(phoneNumber);
}
CFRelease(aRecord);
CFRelease(multi);
精彩评论