@iOS call the library file used to manipulate contacts
Addressbook.framework
Addressbookui.framework
#import "HMTMainViewController.h" #import <AddressBook/AddressBook.h> #import <addressbookui/ Addressbookui.h> @interface Hmtmainviewcontroller () <abpeoplepickernavigationcontrollerdelegate>@ Property (Nonatomic,strong) Abpeoplepickernavigationcontroller *personpickvc; @property (Nonatomic,strong) UIWebView *phonecallwebview, @end @implementation hmtmainviewcontroller-(ID) initwithnibname: (NSString *) NibNameOrNil Bundle: ( NSBundle *) nibbundleornil{self = [super Initwithnibname:nibnameornil Bundle:nibbundleornil]; if (self) {//Custom initialization} return to self;} -(void) viewdidload{[Super Viewdidload]; Do any additional setup after loading the view. Self.navigationItem.title = @ "System Address Book"; Self.navigationItem.leftBarButtonItem = [[Uibarbuttonitem alloc] initwithtitle:@ "delete" style: Uibarbuttonitemstyleplain target:self Action: @selector (didclickdeletepersonaction)]; UIButton *button = [UIButton Buttonwithtype:uibuttontypesystem]; ButtOn.frame = CGRectMake (100, 70, 120, 40); [Button settitle:@ "select Contact" Forstate:uicontrolstatenormal]; [Button addtarget:self action: @selector (Didclickselectaction) forcontrolevents:uicontroleventtouchupinside]; [Self.view Addsubview:button]; }-(void) didclickselectaction{//Select contact for phone book SELF.PERSONPICKVC = [[Abpeoplepickernavigationcontroller alloc] Ini T]; _personpickvc.peoplepickerdelegate = self; _personpickvc.displayedproperties = @[[nsnumber Numberwithint:kabpersonphoneproperty]]; [Self Deleteperson]; [Self PRESENTVIEWCONTROLLER:_PERSONPICKVC animated:yes completion:null]; [Self.navigationcontroller pushviewcontroller:[_personpickvc.viewcontrollers objectatindex:0] Animated:YES]; [Self Getallperson]; }//Enter Select Contact interface-(BOOL) Peoplepickernavigationcontroller: (Abpeoplepickernavigationcontroller *) peoplepicker Shouldcontinueafterselectingperson: (ABRECORDREF) person{//When the contact is selected, exit and return the desired property [Peoplepicker Dismissviewcontroller Animated: YES completion:^{nsstring *firstname = (__bridge nsstring*) abrecordcopyvalue (person, Kabpersonfirstnamepro Perty); NSLog (@ "person =%@", firstName); Abmultivalueref phones = Abrecordcopyvalue (Person,kabpersonphoneproperty); for (int i = 0; i < abmultivaluegetcount (phones); i++) {NSString *phone = (__bridge NSString *) (Abmultivalu Ecopyvalueatindex (phones, i)); NSLog (@ "telephone =%@", phone); } }]; return YES;} -(void) Peoplepickernavigationcontrollerdidcancel: (Abpeoplepickernavigationcontroller *) peoplePicker{[ Peoplepicker Dismissviewcontrolleranimated:yes completion:^{}];} -(BOOL) Peoplepickernavigationcontroller: (Abpeoplepickernavigationcontroller *) peoplepicker Shouldcontinueafterselectingperson: (abrecordref): (Abpropertyid) Property identifier: ( Abmultivalueidentifier) identifier{return YES;} Show all Contacts-(void) getallperson{cfarrayref allperson = AbaddressbookcopyarrAyofallpeople (Self.personPickVC.addressBook); For (ID person in ((__bridge Nsarray *) allperson)) {NSString *firstname = (__bridge nsstring*) abrecordcopy Value ((__bridge abrecordref) person, kabpersonfirstnameproperty); NSLog (@ "firstName =%@", firstName); Because a user may have multiple phones, you need to loop abmultivalueref phones = Abrecordcopyvalue ((__bridge abrecordref) Person,kabpersonphonepr Operty); for (int i = 0; i < abmultivaluegetcount (phones); i++) {NSString *phone = (__bridge NSString *) (Abmultivalu Ecopyvalueatindex (phones, i)); NSLog (@ "telephone =%@", phone); }}}//Add contact-(void) addperson{abaddressbookref addressbook = Self.personPickVC.addressBook; Abrecordref person = abpersoncreate (); Abrecordsetvalue (person, Kabpersonfirstnameproperty, @ "Hu", nil); Abrecordsetvalue (person, Kabpersonlastnameproperty, @ "Minh Toan", nil); Abmutablemultivalueref mulref = abmultivaluecreatemutable (Kabstringpropertytype); for (int i = 0; i < 1; i++) {Abmultivalueidentifier mutableidentifier; Abmultivalueaddvalueandlabel (Mulref, @ "18690231234", Nil, &mutableidentifier); } abrecordsetvalue (person, Kabpersonphoneproperty, mulref, nil); Abaddressbookaddrecord (addressbook, person, nil); Abaddressbooksave (addressbook, nil); }//Delete contact-(void) deleteperson{cfarrayref allperson = abaddressbookcopyarrayofallpeople (Self.personPickVC.addressB Ook); For (ID person in (__bridge Nsarray *) allperson) {NSString *firstname = (__bridge nsstring*) Abrecordcopyva Lue (__bridge abrecordref) person, kabpersonfirstnameproperty); if ([FirstName isequaltostring:@ "Hu"]) {Abaddressbookremoverecord (Self.personPickVC.addressBook, (__bridge Abre CORDREF) person, nil); }} abaddressbooksave (Self.personPickVC.addressBook, nil);} Call-(void) Dialphonenumber: (NSString *) phonenumber{//1.UIWebView load phone nsurl *phoneurl = [Nsurl urlwithstring: [NSString stringwithformat:@ "tel:%@", PhoneNumber]]; Self.phonecallwebview = [[UIWebView alloc] Initwithframe:cgrectzero]; [Self.phonecallwebview loadrequest:[nsurlrequest Requestwithurl:phoneurl]; 2. Private method [[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@ "telprompt://10086"];}