// Read all contacts
-(void) readallpeoples
{
// get local communication record name handle
abaddressbookref tmpaddressbook = abaddressbookcreate();
// get all local contact records
Nsarray* tmppeoples = (nsarray*)abaddressbookcopyarrayofallpeople(Tmpaddressbook);
for (ID tmpperson in Tmppeoples)
{
addresslist *item = [[addresslistalloc]init];
// get Contact single attribute : First Name
nsstring* tmpfirstname = (nsstring*)abrecordcopyvalue(Tmpperson, Kabpersonfirstnameproperty);
NSLog (@ "First name:%@", Tmpfirstname);
// Gets the contact single attribute : Last Name
nsstring* tmplastname = (nsstring*)abrecordcopyvalue(Tmpperson, Kabpersonlastnameproperty);
NSLog (@ "Last name:%@", Tmplastname);
Item. name = [nsstringstringwithformat:@ "%@%@", Tmplastname,tmpfirstname];
// get Contact single attribute : Generic phone number
abmultivalueref tmpphones =abrecordcopyvalue(Tmpperson, Kabpersonphoneproperty);
for (nsinteger j =0; j < Abmultivaluegetcount(tmpphones); j + +)
{
nsstring* tmpphoneindex = (nsstring*)abmultivaluecopyvalueatindex(Tmpphones, J);
NSLog (@ "tmpphoneindex%d:%@", J, Tmpphoneindex);
}
Item. phone = tmpphones;
[dataarrayaddobject: item];
[Tmpfirstnamerelease];
[Tmplastnamerelease];
Cfrelease (Tmpphones);
}
// free memory
[Tmppeoplesrelease];
Cfrelease (Tmpaddressbook);
}
Read all Contacts