// 还是导入
#import <AddressBook/AddressBook.h>
- (void) fetchaddressbookbeforeios9{Abaddressbookref addressbook = Abaddressbookcreate ();User authorizationif (abaddressbookgetauthorizationstatus () = = kabauthorizationstatusnotdetermined) {First Access Address Book abaddressbookrequestaccesswithcompletion (addressbook, ^ (BOOL Granted,Cferrorref error) {if (!error) {if (granted) {Allow Nsarray *contacts = [Self Fetchcontactwithaddressbook:addressbook];Dispatch_async (Dispatch_get_main_queue (), ^{ NSLog (@ "contacts:%@", contacts); }); }else{Refused} }else{NSLog (@ "Error!");});else{Non-first access address BookNsarray *contacts = [Self Fetchcontactwithaddressbook:addressbook];Dispatch_async (Dispatch_get_main_queue (), ^{ NSLog (@ "contacts:%@", contacts); }); }}- (Nsmutablearray *) Fetchcontactwithaddressbook: (abaddressbookref) addressbook{if (abaddressbookgetauthorizationstatus () = = kabauthorizationstatusauthorized) {have permission to accessGet the contact Number groupNsarray *array = (__bridgeNsarray *) abaddressbookcopyarrayofallpeople (addressbook);Nsmutablearray *contacts = [Nsmutablearray array];for (int i =0; I < array. Count; i++) {Get Contact Abrecordref people =Cfarraygetvalueatindex ((__bridge abrecordref) array, i);Get contact details such as name, phone number, address and other informationNSString *firstname = (__bridgeNSString *) Abrecordcopyvalue (people, kabpersonfirstnameproperty);nsstring *lastname = (__bridge nsstring *) abrecordcopyvalue (people, kabpersonlastnameproperty); Abmutablemultivalueref *phonenumref = Abrecordcopyvalue (people, kabpersonphoneproperty); NSString *phonenumber = ((__bridge Nsarray *) abmultivaluecopyarrayofallvalues (phonenumref)). LastObject; [Contacts addobject:@{@ "name": [FirstName Stringbyappendingstring:lastname], @ "PhoneNumber": PhoneNumber}];} return contacts;} else{//No access NSLog (@ "No access to Address Book"); return Nil;}}
iOS get Address Book phone number and name