Header file
#import <AddressBook/AddressBook.h>#import <AddressBookUI/AddressBookUI.h>
Authorized
About the authorization of the Address Book there is no more to say, I mentioned in the previous article: Contacts Authorization
Access Address Book
Jump to System Address Book
-(void) jumpaddress{ *PEOPLEPICKVC = [[Abpeoplepickernavigationcontroller alloc] init]; = self ; [Self PRESENTVIEWCONTROLLER:PEOPLEPICKVC animated:yes completion:nil];}
Add Agent
@interface Viewcontroller () <abpeoplepickernavigationcontrollerdelegate, uinavigationcontrollerdelegate>
Proxy method
/// deselect -(void) Peoplepickernavigationcontrollerdidcancel: (Abpeoplepickernavigationcontroller * ) peoplepicker{ }
///after implementing this method, the following proxy methods will not be implemented (this method is to click the name directly in the Address book list to call and dismiss)- (void) Peoplepickernavigationcontroller: (abpeoplepickernavigationcontroller*) Peoplepicker Didselectperson: (abrecordref) person {//get the current contact nameNSString *firstname= (__bridge NSString *) (Abrecordcopyvalue (person, kabpersonfirstnameproperty)); //get current Contact last nameNSString *lastname= (__bridge NSString *) (Abrecordcopyvalue (person, kabpersonlastnameproperty)); //get an array of phone numbers for the current contactNsmutablearray *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]; } //gets the current contact's mailbox note is an arrayNsmutablearray *emailarray =[[Nsmutablearray alloc]init]; Abmultivalueref emails=Abrecordcopyvalue (person, kabpersonemailproperty); for(Nsinteger j=0; J<abmultivaluegetcount (emails); J + +) {NSString*email = (__bridge NSString *) (Abmultivaluecopyvalueatindex (emails, j)); NSLog (@"email=%@", email); [Emailarray Addobject:email]; } //get the current contact middle nameNSString *middlename= (__bridge nsstring*) (Abrecordcopyvalue (person, kabpersonmiddlenameproperty)); //gets the name prefix of the current contactNSString *prefix= (__bridge nsstring*) (Abrecordcopyvalue (person, kabpersonprefixproperty)); //gets the name suffix of the current contactNSString *suffix= (__bridge nsstring*) (Abrecordcopyvalue (person, kabpersonsuffixproperty)); //get the nickname of the current contactNSString *nickname= (__bridge nsstring*) (Abrecordcopyvalue (person, kabpersonnicknameproperty)); //get the name of the current contact PinyinNSString *firstnamephoneic= (__bridge nsstring*) (Abrecordcopyvalue (person, kabpersonfirstnamephoneticproperty)); //gets the current contact's last name PinyinNSString *lastnamephoneic= (__bridge nsstring*) (Abrecordcopyvalue (person, kabpersonlastnamephoneticproperty)); //gets the middle name of the current contact PinyinNSString *middlenamephoneic= (__bridge nsstring*) (Abrecordcopyvalue (person, kabpersonmiddlenamephoneticproperty)); //get the company of the current contactNSString *organization= (__bridge nsstring*) (Abrecordcopyvalue (person, kabpersonorganizationproperty)); //get the current contact's positionNSString *job= (__bridge nsstring*) (Abrecordcopyvalue (person, kabpersonjobtitleproperty)); //get the Department of the current contactNSString *department= (__bridge nsstring*) (Abrecordcopyvalue (person, kabpersondepartmentproperty)); //get the current contact's birthday//nsstring *birthday= (__bridge nsdate*) (Abrecordcopyvalue (person, kabpersonbirthdayproperty)); //get notes for the current contactNSString *notes= (__bridge nsstring*) (Abrecordcopyvalue (person, kabpersonnoteproperty)); //gets the time to create the current contact note is NSDateNSDate *creattime= (__bridge nsdate*) (Abrecordcopyvalue (person, kabpersoncreationdateproperty)); //gets the time that the current contact was last modifiedNSDate *altertime= (__bridge nsdate*) (Abrecordcopyvalue (person, kabpersonmodificationdateproperty)); //get the current contact avatar pictureNSData *userimage= (__bridge nsdata*) (Abpersoncopyimagedata (person)); //get current Contact anniversaryNsmutablearray *datearr =[[Nsmutablearray alloc]init]; Abmultivalueref dates=Abrecordcopyvalue (person, kabpersondateproperty); for(Nsinteger j=0; J<abmultivaluegetcount (dates); J + +) { //Get Anniversary DateNSDate *data = (__bridge nsdate*) (Abmultivaluecopyvalueatindex (dates, j)); //Get Anniversary nameNSString *str = (__bridge nsstring*) (Abmultivaluecopylabelatindex (dates, j)); }}
/// after implementing this method, the proxy method above will not be implemented (this method is to enter the Address book details after clicking on the name or phone call and dismiss)-(void) Peoplepickernavigationcontroller: ( abpeoplepickernavigationcontroller*) peoplepicker Didselectperson: (abrecordref) Person property: (Abpropertyid) Property identifier: (abmultivalueidentifier) identifier Ns_available_ios (8_0) {}
Note: The above two select callback agent implementation of one can be
Related reference: http://www.jb51.net/article/95500.htm
Ios-Get contact information for contacts