IOS-Get Address Book Contact Information, ios-Address Book Contact

Source: Internet
Author: User

IOS-Get Address Book Contact Information, ios-Address Book Contact
Header file

#import <AddressBook/AddressBook.h>#import <AddressBookUI/AddressBookUI.h>
Authorization

The address book authorization is not mentioned here. I mentioned in the previous article: Address Book authorization.

 

Access address book

Jump to system address book

- (void)jumpAddress{    ABPeoplePickerNavigationController *peoplePickVc = [[ABPeoplePickerNavigationController alloc] init];    peoplePickVc.peoplePickerDelegate = self;    [self presentViewController:peoplePickVc animated:YES completion:nil];}

Add proxy

@interface ViewController ()<ABPeoplePickerNavigationControllerDelegate, UINavigationControllerDelegate>

Proxy Method

/// Cancel the selection-(void) Cancel authentication ickernavigationcontrollerdidcancel :( ABPeoplePickerNavigationController *) Cancel authentication icker {}

 

/// After this method is implemented, the following proxy method will not be implemented (this method is called directly by clicking the name in the address book list and dismiss)-(void) implements authentication ickernavigationcontroller :( ABPeoplePickerNavigationController *) required parameter icker didSelectPerson :( ABRecordRef) person {// obtain the current contact name NSString * firstName = (_ bridge NSString *) (ABRecordCopyValue (person, kABPersonFirstNameProperty )); // obtain the last name of the current contact NSString * lastName = (_ bridge NSString *) (ABRecordCopyValue (person, kABPersonLastNameProperty )); // obtain the current contact's phone array NSMutableArray * phoneArray = [[NSMutableArray alloc] init]; ABMultiValueRef phones = ABRecordCopyValue (person, kABPersonPhoneProperty); for (NSInteger j = 0; j <ABMultiValueGetCount (phones); j ++) {NSString * phone = (_ bridge NSString *) (ABMultiValueCopyValueAtIndex (phones, j )); NSLog (@ "phone = % @", phone); [phoneArray addObject: phone];} // obtain the email address of the current contact. Note that the array NSMutableArray * emailArray = [[NSMutableArray alloc] init]; ABMultiValueRef emails = ABRecordCopyValue (person, kABPersonEmailProperty; j <ABMultiValueGetCount (emails); j ++) {NSString * email = (_ bridge NSString *) (ABMultiValueCopyValueAtIndex (emails, j )); NSLog (@ "email = % @", email); [emailArray addObject: email];} // obtain the intermediate name of the current contact NSString * middleName = (_ bridge NSString *) (ABRecordCopyValue (person, kABPersonMiddleNameProperty); // obtain the name prefix of the current contact NSString * prefix = (_ bridge NSString *) (ABRecordCopyValue (person, kABPersonPrefixProperty )); // obtain the name suffix NSString * suffix = (_ bridge NSString *) (ABRecordCopyValue (person, kABPersonSuffixProperty) of the current contact )); // obtain the nickName NSString * nickName = (_ bridge NSString *) (ABRecordCopyValue (person, kABPersonNicknameProperty) of the current contact )); // obtain the name of the current contact NSString * firstNamePhoneic = (_ bridge NSString *) (ABRecordCopyValue (person, kABPersonFirstNamePhoneticProperty )); // obtain the last name of the current contact NSString * lastNamePhoneic = (_ bridge NSString *) (ABRecordCopyValue (person, kABPersonLastNamePhoneticProperty )); // obtain the intermediate name of the current contact NSString * middleNamePhoneic = (_ bridge NSString *) (ABRecordCopyValue (person, kABPersonMiddleNamePhoneticProperty )); // obtain the company NSString * organization = (_ bridge NSString *) (ABRecordCopyValue (person, kABPersonOrganizationProperty) of the current contact )); // obtain the current contact's position NSString * job = (_ bridge NSString *) (ABRecordCopyValue (person, kABPersonJobTitleProperty )); // obtain the department NSString * department = (_ bridge NSString *) (ABRecordCopyValue (person, kABPersonDepartmentProperty) of the current contact )); // get the current contact's birthday // NSString * birthday = (_ bridge NSDate *) (ABRecordCopyValue (person, kABPersonBirthdayProperty )); // obtain the remarks of the current contact NSString * notes = (_ bridge NSString *) (ABRecordCopyValue (person, kABPersonNoteProperty )); // obtain the time when the current contact is created. Note that NSDate * creatTime = (_ bridge NSDate *) (ABRecordCopyValue (person, kABPersonCreationDateProperty )); // obtain the last modified current contact time NSDate * alterTime = (_ bridge NSDate *) (ABRecordCopyValue (person, kABPersonModificationDateProperty )); // obtain the current contact profile picture NSData * userImage = (_ bridge NSData *) (ABPersonCopyImageData (person )); // obtain the current contact anniversary NSMutableArray * dateArr = [[NSMutableArray alloc] init]; ABMultiValueRef dates = ABRecordCopyValue (person, kABPersonDateProperty); for (NSInteger j = 0; j <ABMultiValueGetCount (dates); j ++) {// obtain the date of the anniversary NSDate * data = (_ bridge NSDate *) (ABMultiValueCopyValueAtIndex (dates, j )); // obtain the anniversary name NSString * str = (_ bridge NSString *) (ABMultiValueCopyLabelAtIndex (dates, j ));}}

 

/// After this method is implemented, the above proxy method will not be implemented (this method is to go to the address book details and click the name or phone number to call it and dismiss)-(void) implements authentication ickernavigationcontroller :( abw.lepickernavigationcontroller *) required parameter icker didSelectPerson :( ABRecordRef) person property :( ABPropertyID) property identifier :( ABMultiValueIdentifier) identifier NS_AVAILABLE_IOS (8_0 ){}

 

Note: You can implement one of the above two callback proxies.

 

Reference: http://www.jb51.net/article/95500.htm

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.