Get iPhone Address Book Information

Source: Internet
Author: User

The contact information in the iPhone is stored in the system database. Each record in the database is an abrecordref instance.

The address book mainly stores two types of records:

1. Contact information: it is of the abperson type. It mainly includes the contact name, phone number, and address information.

2. group information: it is of the abgroup type. Used to group contacts to different groups. It has only one attribute, indicating the group name.

Add the following code to viewdidload to obtain information about all contacts and groups:

ABAddressBookRef addressBook =ABAddressBookCreate();CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople (addressBook);CFArrayRef allGroups = ABAddressBookCopyArrayOfAllGroups(addressBook);for (id person in (NSArray *) allPeople)[self logContact:person];for (id group in (NSArray *) allGroups)[self logGroup:group];CFRelease(allGroups);CFRelease(allPeople);CFRelease(addressBook);

  

Use abaddressbookcreate to create an addressbook instance. Abaddressbook copyarrayofallpeople and abaddressbook copyarrayofallgroups query all contacts and group information. Use the logperson and loggroup methods to output information to the console through a loop.

Logperson method:

CFStringRef name = ABRecordCopyCompositeName(person);
ABRecordID recId = ABRecordGetRecordID(person);
NSLog(@"Person Name: %@ RecordID:%d",name, recId);

Loggroup method:

CFStringRef name = ABRecordCopyValue(group,kABGroupNameProperty);
ABRecordID recId = ABRecordGetRecordID(group);
NSLog(@"Group Name: %@ RecordID:%d",name, recId);

Summary:This article briefly describes how to retrieve the address book information of the iPhone through the SDK.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.