IPhoneApplicationAddress Book ContactThe development case is the content to be introduced in this article. It is mainly about the UITabBarController study notes. Let's take a look at the details. AndAddress bookMediumContactThe application iPhone provides two frameworks: AddressBook. framework and AddressBookUI. framework. With these frameworks, we can access and display them in the program.IPhoneIn the databaseContactInformation.
1. AddressBookUI display
The AddressBookUI provides some controllers related to the display information of contacts. There are four controllers:
ABPeoplePickerNavigationController: displays the entire address book and can select a contact information.
ABPersonViewController: displays the information of a specific contact.
ABNewPersonViewController: adds a new contact.
ABUnknownPersonViewController: improves the information of a contact.
Because the most important part is ABPeoplePickerNavigationController, we will introduce how to display the entire address book through a program and select a contact information.
A) Create and initialize an ABPeoplePickerNavigationController object.
B) set its proxy delegate)
C) use presentModalViewController: animated: 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];
- }
ABPeoplePickerNavigationControllerDelegate
1)
- peoplePickerNavigationControllerDidCancel:
Call this method when the user chooses to cancel the operation. You can cancel the display of the entire address book page in this method.
2)
- peoplePickerNavigationController:shouldContinueAfterSelectingPerson:
This method is called when you select a contact in the address book. You can obtain the contact information here. If you want to continue displaying more specific information about this contact, return YES. Otherwise, cancel the display of the entire address book page and return NO.
3)
- eoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier:
If YES is returned from the previous method, a contact information is displayed. If a record of a contact is selected, this method is called, you can click to select a contact information. If you want to perform further operations on a selected record, such as directly calling a phone or calling an email, return YES. Otherwise, cancel the display of the entire address book page and return NO.
Example:
- -(Void) verify whether ickernavigationcontrollerdidcancel :( ABPeoplePickerNavigationController *) Then restart icker {
- // Assigning control back to the main controller
- [Picker dismissModalViewControllerAnimated: YES];
- }
- -(BOOL) warn about ickernavigationcontroller:
- ShouldContinueAfterSelectingPerson :( ABRecordRef) person {
- // Obtain the contact name
- Name. text = (NSString *) ABRecordCopyCompositeName (person );
- // Obtain the contact phone number
- 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) autorelti];
- NSLog (@ "PhoneLabel: % @ Phone #: % @", aLabel, aPhone );
- If ([aLabel isw.tostring: @ "_ $! <Mobile>! $ _ "])
- {
- [Phones addObject: aPhone];
- }
- }
- PhoneNo. text = @"";
- If ([phones count]> 0)
- {
- NSString * export Eno = [phones objectAtIndex: 0];
- PhoneNo. text = mobileNo;
- // NSLog (ENO );
- }
- // Obtain the contact email address
- 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. text = @"";
- If ([emails count]> 0)
- {
- NSString * emailFirst = [emails objectAtIndex: 0];
- Email. text = emailFirst;
- // NSLog (emailFirst );
- }
- [Commandid icker dismissModalViewControllerAnimated: YES];
- Return NO;
- }
- -(BOOL) warn about ickernavigationcontroller:
- ShouldContinueAfterSelectingPerson :( ABRecordRef) person
- Property :( ABPropertyID) property
- Identifier :( ABMultiValueIdentifier) identifier {
- Return NO;
- }
2. AddressBook
The AddressBook framework mainly records the information of contacts. A ABRecordRef record can be a single-person kABPersonType or a set kABGroupType ).
Each attribute of a contact in the address book can be a single-Value Attribute or a multi-value attribute. A single value attribute corresponds to only one value, such as the contact's name. A multi-value attribute may correspond to multiple values, such as a contact with multiple phone numbers.
A) Common Methods
- CFTypeRef ABRecordCopyValue (
- ABRecordRef record,
- ABPropertyID property
- );
Obtains the value of an attribute from a record.
B) method corresponding to a single value attribute
- CFStringRef ABRecordCopyCompositeName (
- ABRecordRef record
- );
Obtain the full contact name.
C) method corresponding to multi-value Attributes
- CFTypeRef ABMultiValueCopyValueAtIndex (
- ABMultiValueRef multiValue,
- CFIndex index
- );
Returns the attribute value at the corresponding position.
- CFStringRef ABMultiValueCopyLabelAtIndex (
- ABMultiValueRef multiValue,
- CFIndex index
- );
Returns the attribute ID at the corresponding location.
- CFArrayRef ABMultiValueCopyArrayOfAllValues (
- ABMultiValueRef multiValue
- );
Returns an array containing all attribute values.
- CFIndex ABMultiValueGetCount (
- ABMultiValueRef multiValue
- );
Number of returned attribute values
Example:
- // Obtain the contact name
- Name. text = (NSString *) ABRecordCopyCompositeName (person );
- // Obtain the contact phone number
- 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) autorelti];
- NSLog (@ "PhoneLabel: % @ Phone #: % @", aLabel, aPhone );
- If ([aLabel isw.tostring: @ "_ $! <Mobile>! $ _ "])
- {
- [Phones addObject: aPhone];
- }
- }
Summary:IPhoneApplicationAddress Book ContactI hope this article will help you with the introduction of the development case!