ios-System API call contact information

Source: Internet
Author: User

. h file

The system comes with the contact framework

#import <AddressBook/AddressBook.h>

#import <AddressBookUI/AddressBookUI.h>

Plus delegate

Abpeoplepickernavigationcontrollerdelegate

{

Uitextfield * aphonefield;//Patient cell phone Number field

}

/*

Picker

System built-in Contact View object

@property (nonatomic) Abpeoplepickernavigationcontroller *picker

Discussion

This object comes from the introduced Addressbookui.framework, the system's built-in Contact View object

*/

@property (nonatomic) Abpeoplepickernavigationcontroller *picker;

. m file

Click the button to pop up the contact list

-(void) Btnclick: (UIButton *) sender{

if (!self.picker) {

Self.picker = [[Abpeoplepickernavigationcontroller alloc] init];

Place the delegate of the picker to the Controll

Self.picker.modalPresentationStyle = Uimodalpresentationcurrentcontext;

Self.picker.modalInPopover = YES;

Self.picker.modalTransitionStyle = uimodaltransitionstylecoververtical;

Self.picker.peoplePickerDelegate = self;

}

Show a Viewcontroller

[Self PresentViewController:self.picker animated:yes completion:nil];

}

/*

Discussion

This method is called when the user selects an item at the Address Book level list, and all information about the selected contact is obtained by person, but when the selected contact has multiple numbers and we want the user to specify a number explicitly (such as making a call), return Yes to allow the contacts to enter the contact details screen:

*/

-(BOOL) Peoplepickernavigationcontroller: (Abpeoplepickernavigationcontroller *) peoplepicker

Shouldcontinueafterselectingperson: (abrecordref) person

{

nsstring* phone;

Abmultivalueref phonenumbers = Abrecordcopyvalue (person,

Kabpersonphoneproperty);

if (Abmultivaluegetcount (phonenumbers) > 0) {

Phone = (__bridge_transfer nsstring*)

Abmultivaluecopyvalueatindex (phonenumbers, 0);

} else {

Phone = @ "";

}

Phone=[phone stringbyreplacingoccurrencesofstring:@ "-" withstring:@ ""];

Aphonefield.text=phone;

Cfrelease (phonenumbers);

[Self.picker Dismissviewcontrolleranimated:yes Completion:nil];

return NO;

}

/*

Discussion

When the user enters a single contact information (Level two page) Click on a field, will call the following method, return Yes to continue to enter the next, click No not to enter the next step, such as click on the phone, return Yes to call, return no will not call:

*/

-(BOOL) Peoplepickernavigationcontroller: (Abpeoplepickernavigationcontroller *) peoplepicker

Shouldcontinueafterselectingperson: (abrecordref) person

Property: (Abpropertyid) property

Identifier: (abmultivalueidentifier) identifier

{

if (property = = Kabpersonphoneproperty) {

Abmutablemultivalueref Phonemulti = Abrecordcopyvalue (person, property);

int index = Abmultivaluegetindexforidentifier (phonemulti,identifier);

nsstring* phone = [NSString stringwithformat:@ "%@", Abmultivaluecopyvalueatindex (Phonemulti, index)];

Aphonefield.text=phone;

[Self.picker Dismissviewcontrolleranimated:yes Completion:nil];

}

return NO;

}

/*

Discussion

Called when a user leaves a single contact information (Level two page) and clicks on a field

*/

-(void) Peoplepickernavigationcontrollerdidcancel: (Abpeoplepickernavigationcontroller *) PeoplePicker

{

[Self.picker Dismissviewcontrolleranimated:yes Completion:nil];

}

iOS8 after the change, because iOS8 after the structure of the Address Book changes: The first layer is a list of people, click on a person's name into the details of this man.

The first method is to select this person and then call.

-(void) Peoplepickernavigationcontroller: (abpeoplepickernavigationcontroller*) peoplepicker DidSelectPerson: ( ABRECORDREF) person Ns_available_ios (8_0) {

nsstring* phone;

Abmultivalueref phonenumbers = Abrecordcopyvalue (person,

Kabpersonphoneproperty);

if (Abmultivaluegetcount (phonenumbers) > 0) {

Phone = (__bridge_transfer nsstring*)

Abmultivaluecopyvalueatindex (phonenumbers, 0);

} else {

Phone = @ "";

}

Phone=[phone stringbyreplacingoccurrencesofstring:@ "-" withstring:@ ""];

Aphonefield.text=phone;

Cfrelease (phonenumbers);

[Self.picker Dismissviewcontrolleranimated:yes Completion:nil];

}

The second method is called after selecting the person's details.

-(void) Peoplepickernavigationcontroller: (abpeoplepickernavigationcontroller*) peoplepicker DidSelectPerson: ( ABRECORDREF): (Abpropertyid) Property identifier: (abmultivalueidentifier) identifier Ns_available_ios (8_0) {

if (property = = Kabpersonphoneproperty) {

Abmutablemultivalueref Phonemulti = Abrecordcopyvalue (person, property);

int index = Abmultivaluegetindexforidentifier (phonemulti,identifier);

nsstring* phone = [NSString stringwithformat:@ "%@", Abmultivaluecopyvalueatindex (Phonemulti, index)];

Aphonefield.text=phone;

[Self.picker Dismissviewcontrolleranimated:yes Completion:nil];

}

}

ios-System API call contact information

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.