ios - 获取姓名和号码联系人列表地址簿
<p><p>我正在尝试从通讯簿中的联系人中获取 NSLog 名称和号码。
我成功记录了名字,但是我没有成功解决数字的问题。</p>
<p>这是我的代码:</p>
<pre><code>ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
if (addressBook != NULL) {
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
if (granted) {
CFArrayRef allNames = ABAddressBookCopyArrayOfAllPeople(addressBook);
if (allNames != NULL) {
NSMutableArray *names = ;
for (int i = 0; i < CFArrayGetCount(allNames); i++) {
ABRecordRef group = CFArrayGetValueAtIndex(allNames, i);
CFStringRef name = ABRecordCopyCompositeName(group);
;
CFRelease(name);
}
NSLog(@"names = %@", names);
CFRelease(allNames);
}
}
CFRelease(addressBook);
});
}
</code></pre>
<p>也许我必须创建 NSDictionnary ?不知道怎么解决...</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>电话号码是一个<code>ABMultiValueRef</code>:</p>
<pre><code>ABMultiValueRef phones = ABRecordCopyValue(person, kABPersonPhoneProperty);
if (phones != NULL) {
for (NSInteger index = 0; index < ABMultiValueGetCount(phones); index++) {
NSString *phone = CFBridgingRelease(ABMultiValueCopyValueAtIndex(phones, index));
NSString *label = CFBridgingRelease(ABMultiValueCopyLabelAtIndex(phones, index));// either kABHomeLabel or kABPersonPhoneMainLabel or ...
// do something with `phone` and `label`
}
CFRelease(phones);
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 获取姓名和号码联系人列表地址簿,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/31627047/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/31627047/
</a>
</p>
页:
[1]