iOS read contacts get friends Address book information [first name (surname + First name), mobile phone number (multiple numbers), etc.]

Source: Internet
Author: User

First, create Address book object

Self.addressbook=abaddressbookcreatewithoptions (null, NULL);

Request access to the user's address book, regardless of whether or not the block will call

Abaddressbookrequestaccesswithcompletion (Self.addressbook, ^ (bool granted, cferrorref error) {

if (!granted) {

NSLog (@ "Not getting Address Book access! ");

}

});

Abpeoplepickernavigationcontroller *peoplepicker = [[Abpeoplepickernavigationcontroller alloc] init];

Peoplepicker.peoplepickerdelegate = self;

[Self Presentviewcontroller:peoplepicker animated:yes completion:nil];

II. implementation of agency agreements

Abpeoplepickernavigationcontrollerdelegate

Third, the implementation of proxy methods

#pragma mark--abpeoplepickernavigationcontrollerdelegate

-(void) Peoplepickernavigationcontroller: (abpeoplepickernavigationcontroller*) peoplepicker DidSelectPerson: ( ABRECORDREF): (Abpropertyid) Property identifier: (Abmultivalueidentifier) Identifier {

Get information from a record

Abmultivalueref valuesref = Abrecordcopyvalue (person, kabpersonphoneproperty);

LastName is the first name, FirstName, and two strings are concatenated to wholename full name.

NSString *firstname= (__bridge NSString *) abrecordcopyvalue (person, kabpersonfirstnameproperty);//Notice that there is a strong turn, You don't have to release resources.

NSString *lastname= (__bridge NSString *) abrecordcopyvalue (person, kabpersonlastnameproperty);

NSString *[email protected] "";

if (firstname.length>0) {

if (lastname.length>0) {

Wholename=[lastname Stringbyappendingstring:firstname];

}

else{

Wholename=firstname;

}

}

else {

if (lastname.length>0)

{

Wholename=[wholename Stringbyappendingstring:lastname];

}

else{

[email protected] "unknown contact";

}

}

Cfindex index = abmultivaluegetindexforidentifier (valuesref,identifier);

NSString *value = (__bridge NSString *) Abmultivaluecopyvalueatindex (valuesref,index);

[Self Dismissviewcontrolleranimated:yes completion:^{

if (value.length!=0| | wholename.length!=0)

{

Generally read the number will be short-term connection format, the following method can remove the number of the horizontal bar

Nsarray *nbarr=[value componentsseparatedbystring:@ "-"];

NSString *[email protected] "";

for (int i=0; i<nbarr.count; i++) {

FINALYNB=[FINALYNB Stringbyappendingstring:[nbarr Objectatindex:i]];

}

NSLog (@ "%@,%@", WHOLENAME,FINALYNB);

}

}];

}

iOS read contacts get friends Address book information [first name (surname + First name), mobile phone number (multiple numbers), etc.]

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.