2012-07-17 40 views

回答

0

我不知道你的問題現在是否解決了。我只是遇到了同樣的問題。就我所見,iOS不提供「準備就緒」的方式來訪問地址簿中的組,如人員選取器http://developer.apple.com/library/ios/#documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Chapters/UI_Controllers.html
但是,您可以像下面的示例代碼那樣訪問所有組信息(您必須添加錯誤處理),但是您必須自己編寫用戶界面。

CFErrorRef error; 
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions (NULL, &error); 
CFArrayRef groups = ABAddressBookCopyArrayOfAllGroups (addressBook); 
ABRecordRef firstGroup = CFArrayGetValueAtIndex (groups,0); 
CFStringRef nameOfFirstGroup = ABRecordCopyCompositeName (firstGroup); 
CFRelease(nameOfFirstGroup); 
CFArrayRef members = ABGroupCopyArrayOfAllMembers (firstGroup); 
ABRecordRef firstMember = CFArrayGetValueAtIndex (members,0); 
CFStringRef nameOfFirstMember = ABRecordCopyCompositeName (firstMember); 
CFRelease(nameOfFirstMember); 
CFRelease(members); 
CFRelease(groups); 
CFRelease(addressBook); 

編輯:
對不起,上述釋放代碼的不同的對象太早。請在代碼末尾添加CFRelease聲明。

相關問題