如何从通讯录中获取姓名,电子邮件ID和所有电话号码并在我的ios应用中显示? [英] How to fetch name, email id and all phone numbers from addressbook and show in my ios app?

查看:263
本文介绍了如何从通讯录中获取姓名,电子邮件ID和所有电话号码并在我的ios应用中显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用,我想从地址簿中获取所有联系人并显示在我的应用中。我已经获取了所有数据,但问题是,该数据的字母顺序不是升序,电话号码也不是,电子邮件ID应该按名称的正确顺序排列。我将所有数据放在不同的数组中。请给出一些正确的想法。

I am developing an app, in which I want to fetch all the contacts from addressbook and show in my app.I have get all the data but problem is,l this data is not in ascending order alphabetically, also phone numbers, email id should be arrange in proper sequence as names.I have all the data in different different arrays.Please give some idea for correct this.

推荐答案

首先在.m文件中导入< AddressBook / AddressBook.h>

First of all import <AddressBook/AddressBook.h> in Your .m File

ABAddressBookRef addressBook = ABAddressBookCreate();
    CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
    NSMutableArray *allEmails = [[NSMutableArray alloc] initWithCapacity:CFArrayGetCount(people)];
    for (CFIndex i = 0; i < CFArrayGetCount(people); i++) {
        ABRecordRef person = CFArrayGetValueAtIndex(people, i);
        ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
        for (CFIndex j=0; j < ABMultiValueGetCount(emails); j++) {
            NSString* email = (__bridge NSString*)ABMultiValueCopyValueAtIndex(emails, j);
            [allEmails addObject:email];

        }
        CFRelease(emails);
    }
    NSLog(@"All Detils:%@",allEmails);
    CFRelease(addressBook);
    CFRelease(people);

您可以获得上述代码中的所有emailAdress。您将其命名为First name,然后更改。

You Can get all emailAdress as above code.You wnat to First name then change.

ABMultiValueRef Name = ABRecordCopyValue(person, kABPersonFirstNameProperty);

联系电话:

ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);

只有您更改所需的个人财产。

Only You changes person property which you want.

// Property keys
AB_EXTERN const ABPropertyID kABPersonFirstNameProperty;          // First name - kABStringPropertyType
AB_EXTERN const ABPropertyID kABPersonLastNameProperty;           // Last name - kABStringPropertyType
AB_EXTERN const ABPropertyID kABPersonMiddleNameProperty;         // Middle name - kABStringPropertyType
AB_EXTERN const ABPropertyID kABPersonPrefixProperty;             // Prefix ("Sir" "Duke" "General") - kABStringPropertyType
AB_EXTERN const ABPropertyID kABPersonSuffixProperty;             // Suffix ("Jr." "Sr." "III") - kABStringPropertyType
AB_EXTERN const ABPropertyID kABPersonNicknameProperty;           // Nickname - kABStringPropertyType
AB_EXTERN const ABPropertyID kABPersonFirstNamePhoneticProperty;  // First name Phonetic - kABStringPropertyType
AB_EXTERN const ABPropertyID kABPersonLastNamePhoneticProperty;   // Last name Phonetic - kABStringPropertyType
AB_EXTERN const ABPropertyID kABPersonMiddleNamePhoneticProperty; // Middle name Phonetic - kABStringPropertyType
AB_EXTERN const ABPropertyID kABPersonOrganizationProperty;       // Company name - kABStringPropertyType
AB_EXTERN const ABPropertyID kABPersonJobTitleProperty;           // Job Title - kABStringPropertyType
AB_EXTERN const ABPropertyID kABPersonDepartmentProperty;         // Department name - kABStringPropertyType
AB_EXTERN const ABPropertyID kABPersonEmailProperty;              // Email(s) - kABMultiStringPropertyType
AB_EXTERN const ABPropertyID kABPersonBirthdayProperty;           // Birthday associated with this person - kABDateTimePropertyType
AB_EXTERN const ABPropertyID kABPersonNoteProperty;               // Note - kABStringPropertyType
AB_EXTERN const ABPropertyID kABPersonCreationDateProperty;       // Creation Date (when first saved)
AB_EXTERN const ABPropertyID kABPersonModificationDateProperty;   // Last saved date

按字母顺序对该数组排序后

After sort that array in alphabetical order

NSArray *EmailArray = [allEmails sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];

这篇关于如何从通讯录中获取姓名,电子邮件ID和所有电话号码并在我的ios应用中显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆