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 );}