IOS reads Address Book information through app (sorting)

Source: Internet
Author: User

IOS reads Address Book information through the app. When reading Address Book information, it needs to load two packages: AddressBookUI and AddressBook, and introduce the header file.
# Import
# Import
The specific implementation is as follows:

-(Void) readAllPeoples {// define the address book name as addressbook ABAddressBookRef tmpAddressBook = nil; // call different methods to obtain the address book according to the system version if ([[UIDevice currentDevice]. systemVersion floatValue]> = 6.0) {tmpAddressBook = abaddressbookcreatewitexceptions (NULL, NULL); eclipsema = dispatch_semaphore_create (0); Messages (tmpAddressBook, ^ (bool greanted, CFErrorRef error) {dispatch_semaphore_signal (sema) ;}); encrypt (sema, DISPATCH_TIME_FOREVER); dispatch_release (sema);} else {tmpAddressBook = ABAddressBookCreate ();} // failed to get the address book if (tmpAddressBook = nil) {return ;}; // read the information in the address book in array mode NSArray * tmpPeoples = (NSArray *) ABAddressBookCopyArrayOfAllPeople (tmpAddressBook ); // traverse the contact in the address book for (id tmpPerson in tmpshortles) {// obtain the single contact attribute: First name NSString * tmpFirstName = (NSString *) ABRecordCopyValue (tmpPerson, kABPersonFirstNameProperty ); NSLog (@ "First name: % @", tmpFirstName); [tmpFirstName release]; // obtain the single contact attribute: Last name NSString * tmpLastName = (NSString *) ABRecordCopyValue (tmpPerson, kABPersonLastNameProperty); NSLog (@ "Last name: % @", tmpLastName); [tmpLastName release]; // obtain a single contact attribute: nickname NSString * tmpNickname = (NSString *) ABRecordCopyValue (tmpPerson, kABPersonNicknameProperty); NSLog (@ "Nickname: % @", tmpNickname); [tmpNickname release]; // obtain the single contact attribute: Company name NSString * tmpCompanyname = (NSString *) ABRecordCopyValue (tmpPerson, kABPersonOrganizationProperty); NSLog (@ "Company name: % @", tmpCompanyname ); [tmpCompanyname release]; // single attribute of the obtained contact: Job Title NSString * tmpJobTitle = (NSString *) ABRecordCopyValue (tmpPerson, kABPersonJobTitleProperty); NSLog (@ "Job Title: % @ ", tmpJobTitle); [tmpJobTitle release]; // single contact attribute retrieved: Department name NSString * tmpDepartmentName = (NSString *) ABRecordCopyValue (tmpPerson, kabpersondetmparentproperty ); NSLog (@ "Department name: % @", tmpDepartmentName); [tmpDepartmentName release]; // single contact attribute retrieved: Email (s) ABMultiValueRef tmpEmails = ABRecordCopyValue (tmpPerson, kABPersonEmailProperty); for (NSInteger j = 0; ABMultiValueGetCount (tmpEmails); j ++) {NSString * tmpEmailIndex = (NSString *) ABMultiValueCopyValueAtIndex (tmpEmails, j ); NSLog (@ "Emails % d: % @", j, tmpEmailIndex); [tmpEmailIndex release];} CFRelease (tmpEmails); // obtain a single contact attribute: birthday NSDate * tmpBirthday = (NSDate *) ABRecordCopyValue (tmpPerson, kABPersonBirthdayProperty); NSLog (@ "Birthday: % @", tmpBirthday); [tmpBirthday release]; // single contact attribute obtained: Note NSString * tmpNote = (NSString *) ABRecordCopyValue (tmpPerson, kABPersonNoteProperty); NSLog (@ "Note: % @", tmpNote ); [tmpNote release]; // single contact attribute obtained: Generic phone number ABMultiValueRef tmpPhones = ABRecordCopyValue (tmpPerson, kABPersonPhoneProperty); for (NSInteger j = 0; j <ABMultiValueGetCount (tmpPhones ); j ++) {NSString * tmpPhoneIndex = (NSString *) ABMultiValueCopyValueAtIndex (tmpPhones, j); NSLog (@ "tmpPhoneIndex % d: % @", j, tmpPhoneIndex ); [tmpPhoneIndex release];} CFRelease (tmpPhones);} // releases the memory [tmpPeoples release]; CFRelease (tmpAddressBook );}

Related Article

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.