Obtain all attributes of contacts in the address book-the standby post is published by a cocoachina member. Please indicate the source and post address for the post.
Abaddressbookref addressbook = abaddressbookcreate ();
Cfarrayref Results = abaddressbookcopyarrayofallpeople (addressbook );
For (INT I = 0; I <cfarraygetcount (results); I ++)
{
Abrecordref person = cfarraygetvalueatindex (results, I );
// Read firstname
Nsstring * personname = (nsstring *) abrecordcopyvalue (person, kabpersonfirstnameproperty );
If (personname! = Nil)
Textview. Text = [textview. Text stringbyappendingformat: @ "\ n name: % @ \ n", personname];
// Read lastname
Nsstring * lastname = (nsstring *) abrecordcopyvalue (person, kabpersonlastnameproperty );
If (lastname! = Nil)
Textview. Text = [textview. Text stringbyappendingformat: @ "% @ \ n", lastname];
// Read the middlename
Nsstring * middlename = (nsstring *) abrecordcopyvalue (person, kabpersonmiddlenameproperty );
If (middlename! = Nil)
Textview. Text = [textview. Text stringbyappendingformat: @ "% @ \ n", middlename];
// Read the prefix
Nsstring * prefix = (nsstring *) abrecordcopyvalue (person, kabpersonprefixproperty );
If (prefix! = Nil)
Textview. Text = [textview. Text stringbyappendingformat: @ "% @ \ n", prefix];
// Read the suffix
Nsstring * suffix = (nsstring *) abrecordcopyvalue (person, kabpersonsuffixproperty );
If (suffix! = Nil)
Textview. Text = [textview. Text stringbyappendingformat: @ "% @ \ n", suffix];
// Read the nick name.
Nsstring * nickname = (nsstring *) abrecordcopyvalue (person, kabpersonnicknameproperty );
If (nickname! = Nil)
Textview. Text = [textview. Text stringbyappendingformat: @ "% @ \ n", nickname];
// Read the pinyin alphabet of firstname
Nsstring * firstnamephonetic = (nsstring *) abrecordcopyvalue (person, kabpersonfirstnamephoneticproperty );
If (firstnamephonetic! = Nil)
Textview. Text = [textview. Text stringbyappendingformat: @ "% @ \ n", firstnamephonetic];
// Read the pinyin alphabet of lastname
Nsstring * lastnamephonetic = (nsstring *) abrecordcopyvalue (person, kabpersonlastnamephoneticproperty );
If (lastnamephonetic! = Nil)
Textview. Text = [textview. Text stringbyappendingformat: @ "% @ \ n", lastnamephonetic];
// Read the phonetic alphabet of middlename
Nsstring * middlenamephonetic = (nsstring *) abrecordcopyvalue (person, kabpersonmiddlenamephoneticproperty );
If (middlenamephonetic! = Nil)
Textview. Text = [textview. Text stringbyappendingformat: @ "% @ \ n", middlenamephonetic];
// Read Organization
Nsstring * Organization = (nsstring *) abrecordcopyvalue (person, kabpersonorganizationproperty );
If (organization! = Nil)
Textview. Text = [textview. Text stringbyappendingformat: @ "% @ \ n", organization];
// Read jobtitle
Nsstring * jobtitle = (nsstring *) abrecordcopyvalue (person, kabpersonjobtitleproperty );
If (jobtitle! = Nil)
Textview. Text = [textview. Text stringbyappendingformat: @ "% @ \ n", jobtitle];
// Read Department
Nsstring * Department = (nsstring *) abrecordcopyvalue (person, kabpersondepartmentproperty );
If (department! = Nil)
Textview. Text = [textview. Text stringbyappendingformat: @ "% @ \ n", Department];
// Read The Birthday
Nsdate * birthday = (nsdate *) abrecordcopyvalue (person, kabpersonbirthdayproperty );
If (birthday! = Nil)
Textview. Text = [textview. Text stringbyappendingformat: @ "% @ \ n", birthday];
// Read the note memo
Nsstring * Note = (nsstring *) abrecordcopyvalue (person, kabpersonnoteproperty );
If (note! = Nil)
Textview. Text = [textview. Text stringbyappendingformat: @ "% @ \ n", note];
// Time when the record is added for the first time
Nsstring * firstknow = (nsstring *) abrecordcopyvalue (person, kabpersoncreationdateproperty );
Nslog (@ "time when this record was added for the first time % @ \ n", firstknow );
// The last time the record was modified
Nsstring * lastknow = (nsstring *) abrecordcopyvalue (person, kabpersonmodificationdateproperty );
Nslog (@ "Last modified time of this record % @ \ n", lastknow );
// Obtain multiple email values
Abmultivalueref email = abrecordcopyvalue (person, kabpersonemailproperty );
Int emailcount = abmultivaluegetcount (email );
For (INT x = 0; x <emailcount; X ++)
{
// Obtain the email label
Nsstring * emaillabel = (nsstring *) abaddressbookcopylocalizedlabel (abmultivaluecopylabelatindex (email, x ));
// Obtain the email Value
Nsstring * emailcontent = (nsstring *) abmultivaluecopyvalueatindex (email, X );
Textview. Text = [textview. Text stringbyappendingformat: @ "% @: % @ \ n", emaillabel, emailcontent];
}
// Read multi-value addresses
Abmultivalueref address = abrecordcopyvalue (person, kabpersonaddressproperty );
Int COUNT = abmultivaluegetcount (Address );
For (Int J = 0; j <count; j ++)
{
// Obtain the address label
Nsstring * addresslabel = (nsstring *) abmultivaluecopylabelatindex (address, J );
Textview. Text = [textview. Text stringbyappendingformat: @ "% @ \ n", addresslabel];
// Obtain the address 6 attribute under the label
Nsdictionary * personaddress = (nsdictionary *) abmultivaluecopyvalueatindex (address, J );
Nsstring * Country = [personaddress valueforkey :( nsstring *) kabpersonaddresscountrykey];
If (country! = Nil)
Textview. Text = [textview. Text stringbyappendingformat: @ "Country: % @ \ n", country];
Nsstring * city = [personaddress valueforkey :( nsstring *) kabpersonaddresscitykey];
If (City! = Nil)
Textview. Text = [textview. Text stringbyappendingformat: @ "City: % @ \ n", City];
Nsstring * State = [personaddress valueforkey :( nsstring *) kabpersonaddressstatekey];
If (State! = Nil)
Textview. Text = [textview. Text stringbyappendingformat: @ "province: % @ \ n", State];
Nsstring * street = [personaddress valueforkey :( nsstring *) kabpersonaddressstreetkey];
If (street! = Nil)
Textview. Text = [textview. Text stringbyappendingformat: @ "Street: % @ \ n", street];
Nsstring * zip = [personaddress valueforkey :( nsstring *) kabpersonaddresszipkey];
If (zip! = Nil)
Textview. Text = [textview. Text stringbyappendingformat: @ "zip code: % @ \ n", zip];
Nsstring * coutntrycode = [personaddress valueforkey :( nsstring *) kabpersonaddresscountrycodekey];
If (coutntrycode! = Nil)
Textview. Text = [textview. Text stringbyappendingformat: @ "country no.: % @ \ n", coutntrycode];
}
// Obtain multiple dates values
Abmultivalueref dates = abrecordcopyvalue (person, kabpersondateproperty );
Int datescount = abmultivaluegetcount (dates );
For (INT y = 0; y <datescount; y ++)
{
// Obtain the dates label
Nsstring * dateslabel = (nsstring *) abaddressbookcopylocalizedlabel (abmultivaluecopylabelatindex (dates, y ));
// Obtain the dates Value
Nsstring * datescontent = (nsstring *) abmultivaluecopyvalueatindex (dates, y );
Textview. Text = [textview. Text stringbyappendingformat: @ "% @: % @ \ n", dateslabel, datescontent];
}
// Obtain the 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 room
Nslog (@ "it's a person, resource, or room \ n ");
}
// Obtain im multi-value
Abmultivalueref instantmessage = abrecordcopyvalue (person, kabpersoninstantmessageproperty );
For (int l = 1; L <abmultivaluegetcount (instantmessage); L ++)
{
// Obtain the IM label
Nsstring * instantmessagelabel = (nsstring *) abmultivaluecopylabelatindex (instantmessage, L );
Textview. Text = [textview. Text stringbyappendingformat: @ "% @ \ n", instantmessagelabel];
// Obtain the 2 attributes of the label
Nsdictionary * instantmessagecontent = (nsdictionary *) abmultivaluecopyvalueatindex (instantmessage, L );
Nsstring * username = [instantmessagecontent valueforkey :( nsstring *) kabpersoninstantmessageusernamekey];
If (username! = Nil)
Textview. Text = [textview. Text stringbyappendingformat: @ "username: % @ \ n", username];
Nsstring * service = [instantmessagecontent valueforkey :( nsstring *) kabpersoninstantmessageservicekey];
If (service! = Nil)
Textview. Text = [textview. Text stringbyappendingformat: @ "service: % @ \ n", Service];
}
// Read multiple phone values
Abmultivalueref
Phone = abrecordcopyvalue (person, kabpersonphoneproperty );
For (int K = 0; k <abmultivaluegetcount (phone); k ++)
{
// Obtain the telephone label
Nsstring * personphonelabel = (nsstring *) abaddressbookcopylocalizedlabel (abmultivaluecopylabelatindex (phone, k ));
// Obtain the phone number under the label
Nsstring * personphone = (nsstring *) abmultivaluecopyvalueatindex (phone, k );
Textview. Text = [textview. Text stringbyappendingformat: @ "% @: % @ \ n", personphonelabel, personphone];
}
// Obtain multiple URL values
Abmultivalueref url = abrecordcopyvalue (person, kabpersonurlproperty );
For (INT m = 0; m <abmultivaluegetcount (URL); m ++)
{
// Obtain the telephone label
Nsstring * urllabel = (nsstring *) abaddressbookcopylocalizedlabel (abmultivaluecopylabelatindex (URL, m ));
// Obtain the phone number under the label
Nsstring * urlcontent = (nsstring *) abmultivaluecopyvalueatindex (URL, M );
Textview. Text = [textview. Text stringbyappendingformat: @ "% @: % @ \ n", urllabel, urlcontent];
}
// Read the photo
Nsdata * image = (nsdata *) abpersoncopyimagedata (person );
Uiimageview * myimage = [[uiimageview alloc] initwithframe: cgrectmake (200, 0, 50, 50)];
[Myimage setimage: [uiimage imagewithdata: Image];
Myimage. opaque = yes;
[Textview addsubview: myimage];
}
Cfrelease (results );
Cfrelease (addressbook );
Source Address: http://www.cocoachina.com/bbs/read.php? Tid = 62527 & fpage = 2