iPhone:如何获取iPhone上所有通讯录的名称? [英] iPhone: How do you get the names of all the address books on the iPhone?
本文介绍了iPhone:如何获取iPhone上所有通讯录的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于他们使用不同的同步连接(例如, Exchange服务器。
Some users have multiple address books in their iPhone Contacts, as a result of different synchronization connections they have made with e.g. Exchange Servers.
如何获得所有这些不同的地址簿?我想获取保存这些不同通讯录的名称并访问它们的联系信息。
How is it possible to get all of these different address books? I would be interested in getting the names under which these different address books are saved and accessing their contact information.
谢谢!
推荐答案
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef sourcesArray = ABAddressBookCopyArrayOfAllSources(addressBook);
for (CFIndex i = 0; i < CFArrayGetCount(sourcesArray); i++) {
ABRecordRef source = (ABRecordRef)CFArrayGetValueAtIndex(sourcesArray, i);
ABRecordID sourceID = ABRecordGetRecordID(source);
CFNumberRef sourceType = (CFNumberRef)ABRecordCopyValue(source, kABSourceTypeProperty);
CFStringRef sourceName = (CFStringRef)ABRecordCopyValue(source, kABSourceNameProperty);
NSLog(@"source id=%d type=%d name=%@", sourceID, [(NSNumber *)sourceType intValue], sourceName);
CFRelease(sourceType);
if (sourceName != NULL) CFRelease(sourceName); // some source names are NULL
}
CFRelease(sourcesArray);
CFRelease(addressBook);
请注意,自iOS 4起,并非所有来源都返回名称。您可以根据类型提供自己的名称。
Note that, as of iOS 4, not all sources return a name. You may provide your own names based on type.
使用 ABAddressBookCopyArrayOfAllPeopleInSource(addressBook,source)
获取来源。
这篇关于iPhone:如何获取iPhone上所有通讯录的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文