获取名称和号码联系人列表地址簿

时间:2015-07-25 13:38:31

标签: ios objective-c addressbook abaddressbook

我正在尝试从地址簿中的联系人中获取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?我不知道如何解决它......

2 个答案:

答案 0 :(得分:1)

您需要使用返回ABRecordCopyValue(group, kABPersonPhoneProperty)的{​​{1}}。有关详情,请参阅https://stackoverflow.com/a/286281/171089

答案 1 :(得分:1)

电话号码为"boost_terms" = { "field1": 3 } "boost_terms" = ["field1"] "boost_terms" = [3]

ABMultiValueRef