OS allows you to set up Address Book operations. One is to directly operate the address book, and the other is to call the address book UI. The implementation method is as follows:
Add addressbook. Framework to the project.
CodeImplementation:
-( Ibaction ) Onclickbutton :( ID ) Sender
{
Nsmutablearray * Personarray = [[[ Nsmutablearray Alloc ] Init ] Autorelease ];
Abaddressbookref Addressbook = Abaddressbookcreate ();
Nsstring * Firstname , * Lastname , * Fullname ;
Personarray = ( Nsmutablearray *) Abaddressbookcopyarrayofallpeople ( Addressbook );
If ([ Sender tag ] = 0 ) {
For ( ID * Person In Personarray )
{
Firstname = ( Nsstring *) Abrecordcopyvalue ( Person , Kabpersonfirstnameproperty );
Firstname = [ Firstname stringbyappendingformat : @ "" ];
Lastname = ( Nsstring *) Abrecordcopyvalue ( Person , Kabpersonlastnameproperty );
Fullname = [ Firstname stringbyappendingformat : @ "% @" , Lastname ];
Nslog ( @ "===% @" , Fullname );
Abmultivalueref Phones = ( Abmultivalueref ) Abrecordcopyvalue ( Person , Kabpersonphoneproperty );
For ( Int I = 0 ; I < Abmultivaluegetcount ( Phones ); I ++)
{
Nsstring * Phone = ( Nsstring *) Abmultivaluecopyvalueatindex ( Phones , I );
Nslog ( @ "===% @" , Phone );
}
Abmultivalueref Mails = ( Abmultivalueref ) Abrecordcopyvalue ( Person , Kabpersonemailproperty );
For ( Int I = 0 ; I < Abmultivaluegetcount ( Mails ); I ++)
{
Nsstring * Mail = ( Nsstring *) Abmultivaluecopyvalueatindex ( Mails , I );
Nslog ( @ "= % @" , Mail );
}
}
} Else {
// Delete information
// Return all contacts to an array
Cfarrayref Personarray = Abaddressbookcopyarrayofallpeople ( Addressbook );
Cfindex Personcount = Abaddressbookgetpersoncount ( Addressbook );
For ( Int I = 0 ; I < Personcount ; I ++ ){
Abrecordref Ref = Cfarraygetvalueatindex ( Personarray , I );
Cfstringref Firstname1 = Abrecordcopyvalue ( Ref , Kabpersonfirstnameproperty );
Cfstringref Lastname1 = Abrecordcopyvalue ( Ref , Kabpersonlastnameproperty );
Nsstring * Contactfirstlast = [ Nsstring Stringwithformat : @ "% @" , ( Nsstring *) Firstname1 ,( Nsstring *) Lastname1 ];
If ([ Contactfirstlast isequaltostring : @ "Xu Meng" ]) {
// Delete a contact
Abaddressbookremoverecord ( Addressbook , Ref , Nil );
}
}
// Save the phone book
Abaddressbooksave ( Addressbook , Nil );
// Release the memory
// Cfrelease (personref );
// Cfrelease (addressbookref );
}
} Wind fashion Java-JavaScript mogujie.com women's clothing