#import<Foundation/Foundation.h>@interfaceLoadingcontactdata:nsobject//reading Contacts+ (Loadingcontactdata *) shareintance;- (void) Getcontactdata;@end#import "LoadingContactData.h"StaticLoadingcontactdata *_contactdata;@implementationLoadingcontactdata+ (Loadingcontactdata *) shareintance{if(_contactdata = =Nil) {_contactdata=[[Loadingcontactdata alloc]init]; } return_contactdata;}- (void) getcontactdata{cferrorref error=NULL; Abaddressbookref AddressBook= Abaddressbookcreatewithoptions (NULL, &error); if(addressbook) {Nsarray*allcontacts = (__bridge_transfer nsarray*) abaddressbookcopyarrayofallpeople (addressbook); Nsmutablearray*contactsarray = [NsmutablearrayNew]; for(Nsuinteger i =0; I<[allcontacts Count]; i++) {abrecordref ContactPerson=(__bridge abrecordref) allcontacts[i]; //Get Mobile numberAbmultivalueref Phonesref =Abrecordcopyvalue (ContactPerson, Kabpersonphoneproperty); Nsmutablearray*telephonearray =[self getmobilephoneproperty:phonesref]; [Telephonearray Enumerateobjectsusingblock:^(IDobj, Nsuinteger idx, BOOL *stop) {Thcontact*contact =[[Thcontact alloc] init]; //Get First and last names and FullNameNSString *firstname = (__bridge_transfer nsstring*) Abrecordcopyvalue (ContactPerson, Kabpersonfirstnameproperty); NSString*lastname = (__bridge_transfer nsstring*) Abrecordcopyvalue (ContactPerson, Kabpersonlastnameproperty); NSString*fullname = (__bridge_transfer NSString *) Abrecordcopycompositename (ContactPerson); //Set Contact PropertiesContact.firstname =FirstName; Contact.lastname=LastName; if(FullName! =Nil) {Contact.FullName=FullName; } Else if(FirstName! = Nil && LastName! =Nil) {Contact.FullName= [NSString stringWithFormat:@"%@%@", Lastname,firstname]; } Else if(FirstName! =Nil) {Contact.FullName=FirstName; } Else if(LastName! =Nil) {Contact.FullName=LastName; } Else{contact.fullname=@""; } //Get Image if it existsNSData * Imgdata = (__bridge_transfer NSData *) Abpersoncopyimagedatawithformat (ContactPerson, Kabpersonimageformatthumbnail);//contact Avatar (cropped)//NSData *imgdata = (__bridge_transfer NSData *) abpersoncopyimagedata (ContactPerson); //Contact Avatar ArtworkUIImage *userimg =[UIImage Imagewithdata:imgdata]; Contact.image=userimg; if(!contact.image) {contact.image= Mf_pngwithskin (Defaults_skin,@"Icon-avatar.png"); } Contact.phone=[obj Telephonewithreformat]; if([Unity ValidateMobile:contact.phone]) {Contact.recordid= Abrecordgetrecordid (ContactPerson) + [[Contact.phone Substringwithrange:nsmakerange (2,8)] Integervalue]+idx; [Contactsarray Addobject:contact]; } }]; if(phonesref) {cfrelease (phonesref); }} [[Contactdataarray sharecontactdata] setcontactdataarray:contactsarray]; if(addressbook) {cfrelease (addressbook); } } Else{NSLog (@"Error"); }}-(Nsmutablearray *) Getmobilephoneproperty: (abmultivalueref) phonesref{Nsmutablearray*dataarray =[[Nsmutablearray alloc]init]; for(intI=0; I < Abmultivaluegetcount (phonesref); i++) {cfstringref Currentphonevalue=Abmultivaluecopyvalueatindex (Phonesref, i); NSString*phone = (__bridge NSString *) Currentphonevalue; [DataArray Addobject:phone]; } returnDataArray;}@end
iOS reads Address Book data