<span id="Label3"></p>Manage contacts with AddressBook<p><p>The iphone is usually a contacts app that includes all of the Contact's sexual (last name), first name, phone, e-mail address, address, birthday, and other personal Information. Contacts data is saved in its own application sandbox, and other apps cannot access Them.</p></p><p><p>In order to access the contact information stored on the iphone, The iOS system provides the following two frameworks.</p></p> <table border="1" cellspacing="0" cellpadding="0"> <tbody> <tr> <td width="269"><p align="center">Addressbook.framework</p></td> <td valign="top" width="428"><p>Through the series functions provided by the framework, we can develop the program interface to add, delete, change and check the contact information in the mobile PHONE.</p></td> </tr> <tr> <td width="269"><p align="center">Addressbookui.framework</p></td> <td valign="top" width="428"><p>The framework is based on addressbook.framework, which directly contains 4 view controller classes and the corresponding delegation protocols. these special view controllers provide the default user interface to work with contact information in the phone, Developers simply create instances of these view controllers and display Them.</p></td> </tr> <tr> <td colspan="2" width="696"><p>Use the following AddressBook framework</p><p>The AddressBook framework consists of the following 4 sets of APIs</p></td> </tr> <tr> <td width="269"><p align="center">Abaddressbook</p></td> <td valign="top" width="428"><p>The Abaddressbook instance represents the Address Book object, which provides a common programming interface that allows us to access the contact information directly and transparently, regardless of how the contacts are stored in the underlying database. when actually programming, Always abaddressbook-oriented pointer (abaddressbookref) programming</p></td> </tr> <tr> <td width="269"><p align="center">Abrecord</p></td> <td valign="top" width="428"><p>Abrecord represents a common record object that contains a large amount of common data, such as the last name of the contact, the first name, the phone, the message, and so On.</p><p></p><p>Each record has a unique ID in the underlying database, and the ID of the specified record can be obtained through the Abrecordgetrecordid () Function.</p><p>The type of the record can be obtained through the Abrecordgetrecordtype () function</p><p>If the record is a contact, the function returns the Kabpersontype (0) enumeration value;</p><p>The record group, the function returns the Kabgrouptype (1) enumeration Value.</p><p>When actually programmed, it is always programmed for abrecord-oriented pointers (abrecordref).</p></td> </tr> <tr> <td width="269"><p align="center">Abperson</p></td> <td valign="top" width="428"><p>Abperson represents contact Information. typically, a abrecordref of type "kabpersontype" is used to represent contact Information. contact information Stores the Contact's last name, first name, address, e-mail, and phone number, etc., using the View controller ( such as abpersonviewcontroller) to display these contact Information.</p></td> </tr> <tr> <td width="269"><p align="center">Abgroup</p></td> <td valign="top" width="428"><p>Abgroup represents a Group. typically, the group is represented by a abrecordref of type "kabgrouptype". a contact can belong to more than one group, and a group can contain multiple Contacts.</p></td> </tr> <tr> <td colspan="2" width="696"><p>The Abaddressbook framework is a process-oriented approach that provides a number of functions in the framework of the 4 set of Apis.</p><p></p><p></p></td> </tr> </tbody> </table><p><p><span style="color: #ff0000;">Summarize:</span></p></p><p><p>The Abaddressbook function is only responsible for managing the address book, including creating an address book, adding records to the address book, deleting records from the address book, and so On. In addition, It also includes determining whether the user is allowed to access the address book, as well as saving or discarding changes to the address Book.</p></p><p><p>In order to add records to the address book, or to delete records from the address book, you need to use Abrecordref,abrecord to provide functions that are primarily used to access the large number of properties that the Abrecord itself contains.</p></p><p><p>Each abrecord is made up of multiple attributes, and the Contact's last name, first name, phone number, mail, and so on, belong to the Abrecord Attribute.</p></p><p><p></p></p><p><p><span style="font-size: 16px; background-color: #00ffff;">Abrecord provides the following common Functions.</span></p></p> <table border="1" cellspacing="0" cellpadding="0"> <tbody> <tr> <td width="312"><p align="center">BOOL Abrecordsetvalue (abrecordref Record,abpropertyid property, cftyperef value, cferrorref *error)</p></td> <td valign="top" width="406"><p>Set the property attribute in record records to "value". The property must be a constant defined by abperson, abgroup, to represent the various properties of the preset, and different properties require different attribute Values.</p><p>The name of the contact, corresponding to the Kabpersonfirstnameproperty constant, this type of attribute only requires a string value;</p><p>The Contact's phone, which corresponds to the Kabpersonphoneproperty constant, requires a Abmutablemultivalue value for this type of Attribute.</p></td> </tr> <tr> <td width="312"><p align="center">Cftyperef abrecordcopyvalue (abrecordref record, Abpropertyid property)</p></td> <td valign="top" width="406"><p>The function returns the value of the property attribute in the Record.</p></td> </tr> <tr> <td width="312"><p align="center">BOOL Abrecordremovevalue (abrecordref record, Abpropertyid property, cferrorref *error)</p></td> <td valign="top" width="406"><p>The function deletes the value of the property attribute in the record records and returns whether the deletion was Successful.</p></td> </tr> <tr> <td width="312"><p align="center">Cfstringref abrecordcopycompositename (abrecordref record):</p></td> <td valign="top" width="406"><p>This function returns compound name information (including information such as last name \ name \ Organization) in the record records.</p></td> </tr> <tr> <td width="312"><p align="center">Abrecordid Abrecordgetrecordid (abrecordref Record)</p></td> <td valign="top" width="406"><p>The function to get the ID of the record</p></td> </tr> <tr> <td width="312"><p align="center">Abrecordtype Abrecordgetrecordtype (abrecordref Record)</p></td> <td valign="top" width="406"><p>The function to get the type of the record (contact record or group Record)</p></td> </tr> </tbody> </table><p><p><span style="color: #ff0000;">Summarize:</span></p></p><p><p>The Abrecord function is primarily used to manipulate the attributes contained in the record, and if the program is to create or get an existing record, it needs to be supported by the functions provided by abperson, ABGROUP.</p></p><p><p>Abperson provides a number of functions that get abrecord of type "kabpersontype", which can create an empty abrecord to add new records to the address book, or to get abrecord that meet certain criteria from the Phonebook. The Abrecord obtained from the address Book can be deleted or modified, including by id, by Name.</p></p><p><p><span style="font-size: 16px; background-color: #00ffff;">Abgroup provides a number of functions to get Abrecord of type "kabgrouptype", Abgroup contains functions that can either create a new Abrecord or load Abrecord from a database.</span></p></p> <table style="width: 720px;" border="1" cellspacing="0" cellpadding="0"> <tbody> <tr> <td colspan="2" width="727"><p>Abmutablemultivalue provides the following common functions</p></td> </tr> <tr> <td width="471"><p align="center">Abmutablemultivalueref abmultivaluecreatemutable (abpropertytype type):</p></td> <td valign="top" width="256"><p>Create a abmutablemultivalue that manages the property values of the Abpropertytype type</p></td> </tr> <tr> <td width="471"><p align="center">BOOL Abmultivalueaddvalueandlabel (abmutablemultivalueref multivalue, cftyperef value, cfstringref label, Abmultivalueidentifier *outidentifier):</p></td> <td valign="top" width="256"><p align="center">Add a property value to Multivalue. value represents a property value, and a label that represents an attribute value (such as a phone number, which can be set to a label such as "home", "work", etc.)</p><p></p></td> </tr> <tr> <td width="471"><p align="center">BOOL Abmultivaluereplacevalueatindex (abmutablemultivalueref multivalue, cftyperef value, cfindex Index)</p></td> <td valign="top" width="256"><p>Replace the property value at the index index in multivalue with the new value</p></td> </tr> <tr> <td width="471"><p align="center">BOOL Abmultivaluereplacelabelatindex (abmutablemultivalueref multivalue,cfstringref Label,cfindex Index)</p></td> <td valign="top" width="256"><p>Replace the property label at the index index in multivalue with the new label</p></td> </tr> <tr> <td width="471"><p align="center">BOOL Abmultiinsertvalueandlabelatindex (abmutablemultivalueref multivalue,cftyperef value, =CFStringRef label, Cfindex Index,abmultivalueidentifier *outidentifier)</p></td> <td valign="top" width="256"><p>Inserts an attribute value at the index index of the Multivalue. value represents the property value, and label represents the tag for the property Value.</p></td> </tr> <tr> <td width="471"><p align="center">BOOL Abmultivalueremovevalueandlabelatindex (abmutablemultivalueref Multivalue,cfindex Index)</p></td> <td valign="top" width="256"><p>Deletes the attribute value at the index index in Multivalue (both the property value and the property value label).</p></td> </tr> </tbody> </table>Delete a contact<p><p>Deleting a contact is simple, just a few steps below.</p></p><p><p></p></p> <table style="width: 720px;" border="1" cellspacing="0" cellpadding="0"> <tbody> <tr> <td><p align="center">1</p></td> <td valign="top" width="690"><p>Create abaddressbookref, which gets a reference to the Address Book</p></td> </tr> <tr> <td><p align="center">2</p></td> <td valign="top" width="690"><p>Gets the abrecordref that will be deleted, which will get a reference to the record being deleted</p></td> </tr> <tr> <td><p align="center">3</p></td> <td valign="top" width="690"><p>Call the Abaddressbookremoverecord () function to delete the specified record</p></td> </tr> <tr> <td><p align="center">4</p></td> <td valign="top" width="690"><p>Call the Abaddressbooksave () function to save the delete operation to the underlying address book</p></td> </tr> <tr> <td><p align="center">Code</p></td> <td valign="top" width="690"><pre><span style="color: #0000ff;"><span style="color: #0000ff;">@implementation</span></span><span style="color: #000000;"><span style="color: #000000;">Lcviewcontroller</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">) Viewdidload{[super viewdidload];}</span></span>-(ibaction) Deleteperson: (<span style="color: #0000ff;"><span style="color: #0000ff;">ID</span></span><span style="color: #000000;"><span style="color: #000000;">) Sender{cferrorref Error</span></span>=<span style="color: #000000;"><span style="color: #000000;">nil; </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Create abaddressbook, The 1th parameter of the function is temporarily unused, passing directly to null</span></span><span style="color: #000000;"><span style="color: #000000;">Abaddressbookref AB</span></span>= Abaddressbookcreatewithoptions (NULL, &<span style="color: #000000;"><span style="color: #000000;">error);</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(!<span style="color: #000000;"><span style="color: #000000;">Error) { </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">request access to user address Book</span></span><span style="color: #000000;"><span style="color: #000000;">abaddressbookrequestaccesswithcompletion (ab,</span></span>^(<span style="color: #0000ff;"><span style="color: #0000ff;">BOOL</span></span><span style="color: #000000;"><span style="color: #000000;">granted, cferrorref Error) { </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">If the user allows access to the address book</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span><span style="color: #000000;"><span style="color: #000000;">(granted) {</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">get the record with ID 3 from the Address book</span></span><span style="color: #000000;"><span style="color: #000000;">Abrecordref Rec</span></span>= Abaddressbookgetpersonwithrecordid (ab,<span style="color: #800080;"><span style="color: #800080;">3</span></span><span style="color: #000000;"><span style="color: #000000;">); BOOL result</span></span>=<span style="color: #000000;"><span style="color: #000000;">Abaddressbookremoverecord (ab, rec, NULL); </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span><span style="color: #000000;"><span style="color: #000000;">(result) {</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">save changes made by the program to the Address book if it is saved successfully</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span><span style="color: #000000;"><span style="color: #000000;">(abaddressbooksave (ab, NULL)) {[self showalert:@] successfully deleted the contact with ID 3];}</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Else</span></span><span style="color: #000000;"><span style="color: #000000;">{[self showalert:@ error ' When saving the change "];}}</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Else</span></span><span style="color: #000000;"><span style="color: #000000;">{[self showalert:@ ' Delete failed '];}} });}}</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span>) Showalert: (nsstring*<span style="color: #000000;"><span style="color: #000000;">) msg{</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">using Uialertview to display msg information</span></span><span style="color: #000000;">[[[ <span style="color: #000000;">uialertview alloc] initwithtitle:@ "hint" message:msg</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Delegate</span></span><span style="color: #000000;"><span style="color: #000000;">: nil cancelbuttontitle:@ "ok" otherbuttontitles:nil] show];}</span></span></pre><p><p></p></p></td> </tr> </tbody> </table><p><p>IOS-----manage Contacts using AddressBook</p></p></span>
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