Development Goal: This requirement simply reads the Address book information
-(void) loadperson{ abaddressbookref addressbookref = abaddressbookcreatewithoptions (null, NULL); if (abaddressbookgetauthorizationstatus () = = kabauthorizationstatusnotdetermined) { Abaddressbookrequestaccesswithcompletion (Addressbookref, ^ (bool granted, cferrorref error) { Cferrorref *error1 = NULL; Abaddressbookref addressbook = abaddressbookcreatewithoptions (NULL, error1); [Self copyaddressbook:addressbook];} ); else if (abaddressbookgetauthorizationstatus () = = kabauthorizationstatusauthorized) { cferrorref *error = NULL; Abaddressbookref addressbook = abaddressbookcreatewithoptions (NULL, error); [Self copyaddressbook:addressbook]; } else { Dispatch_async (Dispatch_get_main_queue (), ^{ //update interface [Mbprogresshud showerror:@ "No Permissions" Toview: Self.view];} );} }
-(void) Copyaddressbook: (abaddressbookref) addressbook{cfindex numberofpeople = Abaddressbookgetpersoncount ( AddressBook); Cfarrayref people = abaddressbookcopyarrayofallpeople (addressbook); for (int i = 0; i < numberofpeople; i++) {Abrecordref person = cfarraygetvalueatindex (people, I); NSString *firstname = (__bridge NSString *) (Abrecordcopyvalue (person, kabpersonfirstnameproperty)); NSString *lastname = (__bridge NSString *) (Abrecordcopyvalue (person, kabpersonlastnameproperty)); Read MiddleName nsstring *middlename = (__bridge nsstring*) abrecordcopyvalue (person, kabpersonmiddlenameproperty); Read prefix prefix nsstring *prefix = (__bridge nsstring*) abrecordcopyvalue (person, kabpersonprefixproperty); Read suffix suffix nsstring *suffix = (__bridge nsstring*) abrecordcopyvalue (person, kabpersonsuffixproperty); Read nickname called NSString *nickname = (__bridge nsstring*) abrecordcopyvalue (person, KabpersoNnicknameproperty); Read FirstName phonetic transcription nsstring *firstnamephonetic = (__bridge nsstring*) abrecordcopyvalue (person, Kabpersonfirstnamepho Neticproperty); Read LastName phonetic transcription nsstring *lastnamephonetic = (__bridge nsstring*) abrecordcopyvalue (person, kabpersonlastnamephonet Icproperty); Read MiddleName phonetic transcription nsstring *middlenamephonetic = (__bridge nsstring*) abrecordcopyvalue (person, Kabpersonmiddlename Phoneticproperty); Read Organization company NSString *organization = (__bridge nsstring*) abrecordcopyvalue (person, Kabpersonorganizationprop Erty); Read JobTitle work NSString *jobtitle = (__bridge nsstring*) abrecordcopyvalue (person, kabpersonjobtitleproperty); Read Department Department NSString *department = (__bridge nsstring*) abrecordcopyvalue (person, Kabpersondepartmentpropert y); Read Birthday birthday NSDate *birthday = (__bridge nsdate*) abrecordcopyvalue (person, kabpersonbirthdayproperty); Read Note Memo NSString*note = (__bridge nsstring*) abrecordcopyvalue (person, kabpersonnoteproperty); The first time the record was added nsstring *firstknow = (__bridge nsstring*) abrecordcopyvalue (person, kabpersoncreationdateproperty); NSLog (@ "The first time the record was added%@\n", Firstknow); The last time the record was modified nsstring *lastknow = (__bridge nsstring*) abrecordcopyvalue (person, Kabpersonmodificationdatepropert y); NSLog (@ "Last modified time of the record%@\n", Lastknow); Get email multi-value Abmultivalueref email = abrecordcopyvalue (person, kabpersonemailproperty); int emailcount = abmultivaluegetcount (email); for (int x = 0; x < Emailcount; + +) {//Get email Label nsstring* Emaillabel = (__bridge NS string*) Abaddressbookcopylocalizedlabel (abmultivaluecopylabelatindex (email, x)); Get Email value nsstring* emailcontent = (__bridge nsstring*) abmultivaluecopyvalueatindex (email, x); }//Read address multi-value abmultivalueref addressing = Abrecordcopyvalue (persOn, Kabpersonaddressproperty); int count = Abmultivaluegetcount (address); for (int j = 0; J < Count; J + +) {//Get Address label nsstring* Addresslabel = (__bridge nsstring*) Abmultivaluecopylabelatindex (address, j); Get the address under the Label 6 property nsdictionary* personaddress = (__bridge nsdictionary*) Abmultivaluecopyvalueatindex (address, J ); nsstring* country = [personaddress valueforkey: (NSString *) Kabpersonaddresscountrykey]; nsstring* City = [personaddress valueforkey: (NSString *) Kabpersonaddresscitykey]; nsstring* state = [personaddress valueforkey: (NSString *) Kabpersonaddressstatekey]; nsstring* Street = [personaddress valueforkey: (NSString *) Kabpersonaddressstreetkey]; nsstring* zip = [personaddress valueforkey: (NSString *) Kabpersonaddresszipkey]; nsstring* Coutntrycode = [personaddress valueforkey: (NSString *) Kabpersonaddresscountrycodekey]; } Get dates multivalued abmultivalueref dates = Abrecordcopyvalue (person, kabpersondateproperty); int datescount = Abmultivaluegetcount (dates); for (int y = 0; y < Datescount; y++) {//Get dates Label nsstring* Dateslabel = (__bridge NS string*) Abaddressbookcopylocalizedlabel (Abmultivaluecopylabelatindex (dates, y)); Gets the dates value nsstring* datescontent = (__bridge nsstring*) abmultivaluecopyvalueatindex (dates, y); }//Get kind value cfnumberref RecordType = Abrecordcopyvalue (person, kabpersonkindproperty); if (RecordType = = kabpersonkindorganization) {//it ' s a company NSLog (@ "It's a company\n"); } else {//it ' s a person, resource, or NSLog (@ "It's a person, resource, or room\n"); }//Get IM Multi-valued abmultivalueref instantmessage = Abrecordcopyvalue (person, KABPERSONINSTANTMESSAG Eproperty); for (int l = 1; l < ABMultivaluegetcount (Instantmessage); l++) {//Get im Label nsstring* instantmessagelabel = (__bridge nsstring*) Abmultivaluecopylabel Atindex (Instantmessage, L); Gets the 2 property under the label nsdictionary* instantmessagecontent = (__bridge nsdictionary*) Abmultivaluecopyvalueatindex (Inst Antmessage, L); nsstring* username = [Instantmessagecontent valueforkey: (NSString *) Kabpersoninstantmessageusernamekey]; nsstring* service = [instantmessagecontent valueforkey: (NSString *) Kabpersoninstantmessageservicekey]; }//Read phone multi-value Abmultivalueref phone = abrecordcopyvalue (person, kabpersonphoneproperty); for (int k = 0; K<abmultivaluegetcount (phone); k++) {//Get Phone label NSString * Personphonela Bel = (__bridge nsstring*) Abaddressbookcopylocalizedlabel (Abmultivaluecopylabelatindex (phone, k)); Gets the phone value under the label NSString * Personphone = (__bridge Nsstring*) Abmultivaluecopyvalueatindex (phone, k); }//Get URL multi-value abmultivalueref URL = abrecordcopyvalue (person, kabpersonurlproperty); for (int m = 0; m < abmultivaluegetcount (URL); m++) {//Get Phone label NSString * URLLabel = (_ _bridge nsstring*) Abaddressbookcopylocalizedlabel (Abmultivaluecopylabelatindex (URL, m)); Gets the phone value under the label NSString * urlcontent = (__bridge nsstring*) Abmultivaluecopyvalueatindex (url,m); }//Read photo NSData *image = (__bridge nsdata*) abpersoncopyimagedata (person); } cfrelease (people); Cfrelease (addressbook);}
Address Book Development