Operations for adding, deleting, and modifying iPhone address book contacts in the iPhone contact group

Source: Internet
Author: User

IPhone Add/Delete contact group

1. Add addressbook. Framework

2. Add a Contact Group

View code

-( Void  ) Addgroup {  //  Create Group Abaddressbookref AB = Abaddressbookcreate (); cferrorref error; abrecordref Group = Abgroupcreate (); abrecordsetvalue (group, kabgroupnameproperty,  @"  New Group " ,& Error); abaddressbookaddrecord (AB, group, & Error); abaddressbooksave (AB, & Error );  //  Create new person and save to this group Abrecordref record = Abpersoncreate (); bool issuccess; issuccess = Abrecordsetvalue (record, kabpersonnicknameproperty, @"  Groupmember nick name  " ,& Error); issuccess = Abrecordsetvalue (record, kabpersonmiddlenameproperty, @"  Middle name  " ,& Error); abmutablemultivalueref copyofphones = Abmultivaluecreatemutable (kabpersonphoneproperty); cftyperef phone = Cfstr ( "  123000222111  "  ); Abmultivalueaddvalueandlabel (copyofphones, phone, kabpersonphonecancelabel, null); issuccess = Abrecordsetvalue (record, kabpersonphoneproperty, copyofphones ,&Error); issuccess = Abaddressbookaddrecord (AB, record ,& Error); issuccess = Abaddressbooksave (AB ,& Error); abgroupaddmember (group, record, & Error); nslog (  @"  Is success % d  "  , Issuccess); abaddressbooksave (AB, & Error); cfrelease (Group );} 

 

3. Get the Contact Group

View code

-(Nsarray *) Getgroups {nsmutablearray * Groupnames = [[Nsmutablearray alloc] init] autorelease]; abaddressbookref AB = Abaddressbookcreate (); nsarray * Array = (nsarray * ) Abaddressbookcopyarrayofallgroups (AB );  For ( Int I = 0 ; I <[array count]; I ++ ) {Abrecordref Group = [Array objectatindex: I]; cftyperef groupname =Abrecordcopyvalue (group, kabgroupnameproperty); nsstring * Groupnamestr = [nsstring stringwithformat: @"  % @  " , (Nsstring * ) Groupname]; nslog (  @"  Groupnames is % @  "  , Groupnamestr); [groupnames addobject: groupnamestr]; cfrelease (groupname );}  Return  Groupnames ;} 

4. delete a Contact Group

View code

//  Delete all Groups -( Void  ) Deletegroups {abaddressbookref AB = Abaddressbookcreate (); cferrorref error;  //  Get all Groups Cfarrayref groups = Abaddressbookcopyarrayofallgroups (AB );  //  Groups 'count Cfindex groupcount = Abaddressbookgetgroupcount (AB );  For ( Int I = 0 ; I <groupcount; I ++ ) {Abrecordref Group = Cfarraygetvalueatindex (groups, I );  //  Delete Abaddressbookremoverecord (AB, group ,& Error); abaddressbooksave (AB, & Error); cfrelease (groups );} 

5. For more information about contact operations, see myArticle: Add, delete, and modify iPhone address book contacts

6. Reference articles written in this article: iPhone address book operation, abaddressbook delete contacts and Groups

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.