Address Book (1) in iOS (self-made simple view version) and ios address book

Source: Internet
Author: User

Address Book (1) in iOS (self-made simple view version) and ios address book

  • In iOS, there are two frameworks for accessing users' address book
    • Provides the contact list interface, contact details interface, and add contact interface.
    • Used to select a contact

2. AddressBook. framework

      • The C-language API only obtains contact data.
      • No UI display is provided. You need to set up a contact display interface by yourself.
      • Most of the data types are based on the Core Foundation framework.
  • Start with iOS6. You must obtain user authorization to access the address book. Therefore, before using the address book, you must check whether the user has been authorized.

 

1. Generate a contact Controller

1-(void) touchesBegan :( NSSet *) touches withEvent :( UIEvent *) event 2 {3 // 1. create a contact on the page 4 ABPeoplePickerNavigationController * ppnc = [[ABPeoplePickerNavigationController alloc] init]; 5 6 // 2. set proxy 7 ppnc. required required ickerdelegate = self; 8 9 // 3. pop-up page 10 [self presentViewController: ppnc animated: YES completion: nil]; 11}

2. Proxy Method

1) called when a contact is clicked

1 // system comment: Called after a person has been selected by the user. 2 // call the method after a person is called a user after being selected. 3 // when a contact is selected, the proxy method 4 is executed. // method: if this method is implemented, the contact's detailed interface 5-(void) authentication ickernavigationcontroller :( ABPeoplePickerNavigationController *) authentication icker didSelectPerson :( ABRecordRef) person NS_AVAILABLE_IOS (8_0) is not displayed) {6 7 // 1. obtain the name of the selected contact (lastname and firstname) 8 CFStringRef firstname = ABRecordCopyValue (person, kABPersonFirstNameProperty); 9 CFStringRef lastname = ABRecordCopyValue (person, kABPersonLastNameProperty ); 10 NSString * firstName = (_ bridge_transfer NSString *) (firstname); 11 NSString * lastName = (_ bridge_transfer NSString *) (lastname ); 12 NSLog (@ "% @", firstName, lastName); 13 14 // 2. get the contact's phone number 15 ABMultiValueRef phones = ABRecordCopyValue (person, kABPersonPhoneProperty); 16 CFIndex count = ABMultiValueGetCount (phones); 17 for (CFIndex I = 0; I <count; I ++) {18 NSString * phoneLabel = (_ bridge_transfer NSString *) values (phones, I); 19 NSString * phoneValue = (_ bridge_transfer NSString *) values (phones, i); 20 NSLog (@ "label: % @ value: % @", phoneLabel, phoneValue); 21} 22 23 // 3. release unused Objects 24 CFRelease (phones); 25 26}

2) called when you click the contact property

1 // Called after a property has been selected by the user. 2 // Literal Translation: an attribute is selected by the user and Called. 3 // Description: This proxy method is executed when you select the attributes of a contact. 4 // method: if this method is implemented, When you select the attributes of a contact, the Controller will be released. will not go to the next page 5 // parameter: arg1: property selected Attribute identifier: Each attribute is identified by a corresponding 6-(void) leplepickernavigationcontroller :( ABPeoplePickerNavigationController *) cannot access icker didSelectPerson :( ABRecordRef) person property :( ABPropertyID) property identifier :( ABMultiValueIdentifier) identifier NS_AVAILABLE_IOS (8_0) {7 8 NSLog (@ "selected an attribute of a contact"); 9 10}

3) click Cancel to call

 

1 // Called after the user has pressed cancel.2 // call after the user is Called a user after the user is canceled, will execute this proxy method 4-(void) peoplePickerNavigationControllerDidCancel :( abpeopleplepickernavigationcontroller *) peoplePicker {5 6 NSLog (@ "the user clicked the cancel button"); 7 8}

 

Not complete ~~~~~

By: Coder, PSS

 

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.