Contacts iOS how to use iOS addressbook

Source: Internet
Author: User

A Basic knowledge

Apps associated with contacts in Contacts the iphone offers two frames: Addressbook.framework and addressbookui.framework, which we can access in the program and display contact information from the iphone database.

Two Specific introduction

1.AddressBookUI Display Section

There are four controllers in the Addressbookui that are associated with displaying information about the contact person:

Abpeoplepickernavigationcontroller: Displays the entire Address book and can select a contact's information

Abpersonviewcontroller: Displays information for a specific contact

Abnewpersonviewcontroller: Add a new contact

Abunknownpersonviewcontroller: Perfecting the information of a contact person


Since the most important of these is abpeoplepickernavigationcontroller, the procedure for displaying the entire address book through the program and the ability to select one of the contact information is described in detail.

(a) creation and initialization of a Abpeoplepickernavigationcontroller object

(b) Setting up its agent (delegate)

(c) Use presentmodalviewcontroller:animated: This method to display the entire Address Book page

Example:

-(Ibaction) Showpicker: (ID) Sender {

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

Picker.peoplepickerdelegate = self;


[Self presentmodalviewcontroller:picker animated:yes];

[Picker release];

}


Introduction to the method of Abpeoplepickernavigationcontrollerdelegate

(a)Peoplepickernavigationcontrollerdidcancel: This method is called when the user chooses to cancel, which cancels the display of the entire Address Book page in this method.

(b)Peoplepickernavigationcontroller:shouldcontinueafterselectingperson: This method is called when the user selects a contact in the Address Book. You can get the contact information here. Return YES If you want to continue to display this contact's more specific information. Otherwise, cancel the display of the entire Address Book page and return NO.

(c)PeoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier: If the previous method returns Yes, a contact information is displayed, and if a record of the contact is selected, the method is called, which can be clicked to select a contact's information. Return YES If you want to be able to do further work on a selected record, such as making a call directly or calling the mailbox to send the message. Otherwise, cancel the display of the entire Address Book page and return NO.

Example:

(a) Example:

-(void) Peoplepickernavigationcontrollerdidcancel: (Abpeoplepickernavigationcontroller *) PeoplePicker {

Assigning control back to the main controller
[Picker Dismissmodalviewcontrolleranimated:yes];
}

(b) Example:

-(BOOL) Peoplepickernavigationcontroller: (Abpeoplepickernavigationcontroller *) peoplepicker Shouldcontinueafterselectingperson: (abrecordref) person
{


Get Name of contact person
Name.text = (nsstring*) abrecordcopycompositename (person);


Get Contact Phone

Abmutablemultivalueref Phonemulti = Abrecordcopyvalue (person, kabpersonphoneproperty);

Nsmutablearray *phones = [[Nsmutablearray alloc] init];

int i;

for (i = 0; i < Abmultivaluegetcount (phonemulti); i++)
{

NSString *aphone = [(nsstring*) Abmultivaluecopyvalueatindex (Phonemulti, i) autorelease];

NSString *alabel = [(nsstring*) Abmultivaluecopylabelatindex (Phonemulti, i) autorelease];

NSLog (@ "phonelabel:%@ phone#:%@", Alabel,aphone);

if ([Alabel isequaltostring:@ "_$!<mobile>!$_"])

{
[Phones Addobject:aphone];
}
}

[Email protected] "";

if ([Phones count]>0)

{
NSString *mobileno = [Phones objectatindex:0];
Phoneno.text = Mobileno;
NSLog (Mobileno);

}
Get Contact mailbox Abmutablemultivalueref Emailmulti = Abrecordcopyvalue (person, kabpersonemailproperty);

Nsmutablearray *emails = [[Nsmutablearray alloc] init];

for (i = 0;i < Abmultivaluegetcount (emailmulti); i++)

{
NSString *emailadress = [(nsstring*) Abmultivaluecopyvalueatindex (Emailmulti, i) autorelease];

[Emails addobject:emailadress];
}

[Email protected] "";

if ([emails count]>0)

{
NSString *emailfirst=[emails objectatindex:0];
Email.text = Emailfirst;
NSLog (Emailfirst);
}

[Peoplepicker Dismissmodalviewcontrolleranimated:yes];

return NO;

}

(c) Example

-(BOOL) Peoplepickernavigationcontroller: (Abpeoplepickernavigationcontroller *) peoplepicker
Shouldcontinueafterselectingperson: (abrecordref): (Abpropertyid) property
Identifier: (abmultivalueidentifier) identifier
{
return NO;
}



2.AddressBook part

The AddressBook framework section primarily records the individual information of a contact, and records of abrecordref types can either represent a single person (Kabpersontype) or a collection (Kabgrouptype).

The various properties of contacts in the Address Book are in two forms, single-valued and multi-valued properties. There is only one value for the single-valued attribute, such as the name of the contact, or multiple values for the multivalued attribute, such as multiple phone numbers for the contact person.

(a) Common methods

Cftyperef Abrecordcopyvalue (

Abrecordref Record,

Abpropertyid Property

);

Get the value of a property from a record

(b) The corresponding method of the single-valued attribute

Cfstringref Abrecordcopycompositename (

Abrecordref Record

);

Gets the full name of the contact.

(c) The method of the multi-valued attribute

Cftyperef Abmultivaluecopyvalueatindex (

Abmultivalueref Multivalue,

Cfindex Index

);

Returns the property value at the corresponding position

Cfstringref Abmultivaluecopylabelatindex (

Abmultivalueref Multivalue,

Cfindex Index

);

Returns the identity of the property at the corresponding location

Cfarrayref Abmultivaluecopyarrayofallvalues (

Abmultivalueref multivalue

);

Returns an array containing all the property values

Cfindex Abmultivaluegetcount (

Abmultivalueref multivalue

);

Returns the number of property values transferred from: http://www.cnblogs.com/y041039/archive/2012/03/22/2411771.html

Contacts iOS how to use iOS addressbook

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.