Dav*_*ave 10 iphone addressbook ios abrecordref
我想获得一个ABPersonRef和ABGroupRef的所有属性的列表,而不必使用kABPersonFirstNameProperty的iOS预定义键,kABPersonLastNameProperty ...我正在使用地址簿,我想迭代所有的值一个特定的人.我知道有预定义的键,但Apple将来可以很好地添加新键,所以我想做类似的事情:
ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *allPeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
for (int i = 0; i < [allPeople count]; ++i) {
ABRecordRef person = [allPeople objectAtIndex:i];
// This is the line that I can't figure out.
NSArray *allProperties = (NSArray *)ABRecordCopyArrayOfAllProperties(person);
}
Run Code Online (Sandbox Code Playgroud)
我知道我会遇到多个项目,我将不得不稍后循环,但目标是获取一个键列表,我可以迭代单值属性.我不在乎返回的类是什么,NSArray,NSDictionary ......无论如何.
我非常感谢任何建议!
您可以尝试以下方法:
使用ARC:
NSDictionary* dictionaryRepresentationForABPerson(ABRecordRef person)
{
NSMutableDictionary* dictionary = [NSMutableDictionary dictionary];
for ( int32_t propertyIndex = kABPersonFirstNameProperty; propertyIndex <= kABPersonSocialProfileProperty; propertyIndex ++ )
{
NSString* propertyName = CFBridgingRelease(ABPersonCopyLocalizedPropertyName(propertyIndex));
id value = CFBridgingRelease(ABRecordCopyValue(person, propertyIndex));
if ( value )
[dictionary setObject:value forKey:propertyName];
}
return dictionary;
}
Run Code Online (Sandbox Code Playgroud)
也许只要propertyName不变成属性就可以了解它UNKNOWN_PROPERTY
| 归档时间: |
|
| 查看次数: |
6379 次 |
| 最近记录: |