IOS Contacts-Get Contact properties

Source: Internet
Author: User

The content is from the iOS development guide of Dongsheng Teacher

Some knowledge that has been written about the contact framework

Now write about reading the contact data related actions

To read the Address Book database, you need

    1. Create Address Book Object
    2. Query fetch data (all or part)
    3. Get Address Book a record (all data for an individual)
    4. Get the various attribute data for this person
That's it
Cferrorref error = NULL;    Create an Address Book Action object    abaddressbookref addressbook = abaddressbookcreatewithoptions (NULL, &error);

The first parameter is the reserved parameter, passing null;
Find contact-(void) Filtercontentforsearchtext: (NSString *) searchtext{    //Determine authorization status    if ( Abaddressbookgetauthorizationstatus ()!=kabauthorizationstatusauthorized) {        return;    }    Cferrorref error = NULL;    Abaddressbookref addressbook = abaddressbookcreatewithoptions (NULL, &error);    if (Searchtext.length = = 0) {        //Find all        listcontacts = Cfbridgingrelease (Abaddressbookcopyarrayofallpeople ( AddressBook));    }    else{        //Find prefix keyword based on string        cfstringref Cfsearchtext = (cfstringref) cfbridgingretain (searchtext);        Listcontacts = Cfbridgingrelease (Abaddressbookcopypeoplewithname (AddressBook, Cfsearchtext));        Cfrelease (Cfsearchtext);    }    This should refresh the table    [Self.tableview reloaddata];    Cfrelease (addressbook);}
Status of Authorization:   kabauthorizationstatusnotdetermined  User has not yet decided   kabauthorizationstatusrestricted  , restricted   kabauthorizationstatusdenied,  refusing   kabauthorizationstatusauthorized  permission
Properties of the contact person
Kabpersonfirstnameproperty;          Name Kabpersonlastnameproperty;           Surname Kabpersonmiddlenameproperty;         Middle name Kabpersonprefixproperty;             Prefix kabpersonsuffixproperty;             suffix kabpersonnicknameproperty;           Nickname Kabpersonfirstnamephoneticproperty;  The name of the Hanyu Pinyin or phonetic kabpersonlastnamephoneticproperty;   Surname Pinyin or phonetic kabpersonmiddlenamephoneticproperty; The middle name of Hanyu Pinyin or phonetic kabpersonorganizationproperty;       Organization name Kabpersonjobtitleproperty;           Job title Kabpersondepartmentproperty;         Department Kabpersonnoteproperty;               Remark Kabpersonbirthdayproperty;           Birthday Kabpersoncreationdateproperty;       Creation time Kabpersonmodificationdateproperty;   Date Modified
    Multivalued attributes (multiple values in one property) have labels, values, id    kabpersonphoneproperty;        Phone number attribute           kabmultistringpropertytype;//type    kabpersonemailproperty;        e-mail attribute            kabmultistringpropertytype;//type    kabpersonurlproperty;          URL attribute               kabmultistringpropertytype;//type    kabpersonrelatednamesproperty;  Kinship person attribute         kabmultistringpropertytype;//type    kabpersonaddressproperty;      Address attribute               kabmultidictionarypropertytype;//type    kabpersoninstantmessageproperty;//Instant Chat property            kabmultidictionarypropertytype;//type    kabpersonsocialprofileproperty;//Social account properties            kabmultidictionarypropertytypel;//type

Use the properties above to find the desired value
The following are single-valued properties:
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{    static NSString *cellidentifier = @ "Cell";    UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:cellidentifier];    if (cell) {        cell = [[UITableViewCell alloc]initwithstyle:uitableviewcellstyledefault Reuseidentifier: Cellidentifier];    }    Get a piece of data from the searched contact group into abrecordref format    abrecordref Thisperson = Cfbridgingretain ([listcontacts objectatindex:[ Indexpath Row]]);    Find the name in this record    nsstring *firstname = Cfbridgingrelease (Abrecordcopyvalue (Thisperson, Kabpersonfirstnameproperty) );    FirstName = firstName! = nil? firstname:@ "";    Find the last name in this record    nsstring *lastname = Cfbridgingrelease (Abrecordcopyvalue (Thisperson, Kabpersonlastnameproperty)) ;    Cell.textLabel.text = [NSString stringwithformat:@ "%@%@", Firstname,lastname];    Cfrelease (Thisperson);    return cell;}


Here's how to find a multivalued property:
//get multi-valued attribute-(void) multivalueproperty{abrecordid personrecordid = [Personidasnumber    Intvalue];//personidasnumber is the value of the NSNumber type used to hold the value of RecordID cferrorref error = NULL;    Abaddressbookref addressbook = abaddressbookcreatewithoptions (NULL, &error); Find Abrecord abrecordref Personrecord = Abaddressbookgetpersonwithrecordid via the Abrecordid property (AddressBook,    Personrecordid);    Find multivalued properties by Abrecord abmultivalueref Emailproperty = Abrecordcopyvalue (Personrecord, Kabpersonemailproperty);    Convert multiple values of multivalued attributes to arrays Nsarray * Emailarray = Cfbridgingrelease (Abmultivaluecopyarrayofallvalues (Emailproperty));        for (int index = 0; index < emailarray.count; index++) {NSString *email = [Emailarray objectatindex:index];        NSString *emaillabel = Cfbridgingrelease (Abmultivaluecopylabelatindex (Emailproperty, index));        Determine the current worthy tag if ([Emaillabel isequaltostring: (NSString *) Kabworklabel]) {NSLog (@ "%@", email); }    }}

Get a picture of a contact:
Get a picture of a contact-(void) setimage{    cferrorref error = NULL;    Abaddressbookref addressbook = abaddressbookcreatewithoptions (NULL, &error);    Abrecordref cecordref = Abaddressbookgetpersonwithrecordid (Addressbook,[personidasnumber intValue]);    Determine if a contact has a photo    if (Abpersonhasimagedata (cecordref)) {        //Get photo data        NSData *photodata = Cfbridgingrelease ( Abpersoncopyimagedata (Cecordref));        Self.imageView.image = [UIImage imagewithdata:photodata];    }}





IOS Contacts-Get Contact properties

Related Article

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.