获取 iPhone 上电话号码给出的姓名

发布于 2024-08-30 16:06:37 字数 140 浏览 4 评论 0原文

我正在使用用户输入电话号码的文本字段。当 TextField 更改时,它应该检查该号码是否已在电话簿中并显示名称。

到目前为止,我唯一的方法是解析字典中的所有名称和数字并从那里读取它。

有没有更简单、更高效、更复杂的方法来做到这一点?

I'm using a TextField where the user types a phone number. When the TextField changes, it should check if this number is already in the phonebook and display the name.

So far, my only way is to parse all names and number in a Dict and read it from there.

Is there a simpler, more efficient and sophisticated way to do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

长途伴 2024-09-06 16:06:37

翻阅用户的地址簿并创建电话号码到人员的映射并不困难。 地址簿编程指南 列出了有关该框架如何工作的所有信息。

It wouldn't be hard to rip through the user's address book and create a phone number to person mapping. The Address Book Programming Guide lays out all the information on how the framework works.

浊酒尽余欢 2024-09-06 16:06:37

在这里关闭并完成这个问题是我的解决方案的主要部分:

ABAddressBookRef m_addressbook = ABAddressBookCreate();
if (!m_addressbook) {
    NSLog(@"opening address book");
}

CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(m_addressbook);
CFIndex nPeople = ABAddressBookGetPersonCount(m_addressbook);

[.....]

adressList = [[NSMutableDictionary alloc] init];

for (int i=0;i < nPeople;i++) { 
    ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i);

    vorname = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
    nachname = ABRecordCopyValue(ref, kABPersonLastNameProperty);
    nameTag = [NSString stringWithFormat:@"%@ %@.", vorname, nachname];

    ABMultiValueRef phones =(NSString*)ABRecordCopyValue(ref, kABPersonPhoneProperty);

    // Loop thru all numbers of a person

    for(CFIndex i = 0; i < ABMultiValueGetCount(phones); i++) {
        tmpNumber = (NSString*)ABMultiValueCopyValueAtIndex(phones, i);
        tmpNumber = [self cleanupPhoneNumber:tmpNumber];
        [adressList setObject: nameTag forKey:tmpNumber];
        NSLog(@"Name: %@ | Phone: %@", nameTag, tmpNumber);
    }
}

To close and complete this issue here is the main part of my solution:

ABAddressBookRef m_addressbook = ABAddressBookCreate();
if (!m_addressbook) {
    NSLog(@"opening address book");
}

CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(m_addressbook);
CFIndex nPeople = ABAddressBookGetPersonCount(m_addressbook);

[.....]

adressList = [[NSMutableDictionary alloc] init];

for (int i=0;i < nPeople;i++) { 
    ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i);

    vorname = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
    nachname = ABRecordCopyValue(ref, kABPersonLastNameProperty);
    nameTag = [NSString stringWithFormat:@"%@ %@.", vorname, nachname];

    ABMultiValueRef phones =(NSString*)ABRecordCopyValue(ref, kABPersonPhoneProperty);

    // Loop thru all numbers of a person

    for(CFIndex i = 0; i < ABMultiValueGetCount(phones); i++) {
        tmpNumber = (NSString*)ABMultiValueCopyValueAtIndex(phones, i);
        tmpNumber = [self cleanupPhoneNumber:tmpNumber];
        [adressList setObject: nameTag forKey:tmpNumber];
        NSLog(@"Name: %@ | Phone: %@", nameTag, tmpNumber);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文