gpt4 book ai didi

ios - 获取姓名和号码联系人列表地址簿

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:58:38 25 4
gpt4 key购买 nike

我正在尝试从地址簿中的联系人中获取 NSLog 姓名和号码。登录名字成功,但是解决号码问题没有成功。

这是我的代码:

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 = [NSMutableArray array];
for (int i = 0; i < CFArrayGetCount(allNames); i++) {
ABRecordRef group = CFArrayGetValueAtIndex(allNames, i);
CFStringRef name = ABRecordCopyCompositeName(group);
[names addObject:(__bridge NSString *)name];
CFRelease(name);
}


NSLog(@"names = %@", names);
CFRelease(allNames);
}
}
CFRelease(addressBook);
});
}

也许我必须创建 NSDictionnary ?不知道怎么解决。。。

最佳答案

电话号码是一个ABMultiValueRef:

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);
}

关于ios - 获取姓名和号码联系人列表地址簿,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31627047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com