Contacts-(IOS9 unique method)

Source: Internet
Author: User

Import library files #import <ContactsUI/ContactsUI.h>

#pragma mark IOS9 a new way to get information from the click of Contacts

#pragma mark- eject the contact controller first

-(ibaction) ios9clicked: (ID) Sender {

//1. Create a controller

Cncontactpickerviewcontroller * picker = [cncontactpickerviewcontroller new];

//2. set up proxy

Picker. delegate = self;

//3. set related properties, predicate filter The email address is a contact for @mac. com

Picker. predicateforselectionofproperty = [nspredicate predicatewithformat:@ "(key = = ') EmailAddresses ') and (value like ' * @mac. com ') "];

// predicates filter contacts with an email address equal to 1

Picker. predicateforselectionofcontact = [nspredicate predicatewithformat:@ "[Email Protected] = = 1 "];

//4. Popup

[self presentviewcontroller: Picker animated:YES completion:Nil ];

}

#pragma mark- when the contact is deselected, it is triggered by clicking Cancel in the upper-right corner instead of all dismiss actions in the picker. In multi-select mode,Cancel is on the left side of done.

-(void) Contactpickerdidcancel: (cncontactpickerviewcontroller *) Picker {

NSLog(@ "Mxs clicked Cancel ");

}

Four other proxy methods just implement one of them. For the single and multiple selection of two groups, when implemented, multi-select priority execution, the radio does not execute. The special note is predicateforenablingcontact,predicateforselectionofcontact, Predicateforselectionofproperty These three sets of properties can affect their actions. predicateforenablingcontact The contact person who returns Yes is interoperable, and the default contact is interactive.

original link:http://www.jianshu.com/p/e6b7cb1eca9e

#pragma mark- called when a contact is selected (if the predicateforselectionofcontact property is not set or matches the filter criteria, Does not trigger the method and enters the contact details page if not met

-(void) Contactpicker: (cncontactpickerviewcontroller *) Picker didselectcontact: (cncontact *) Contact {

//1. Get name ,givenName = = FirstName

NSLog(@ "GivenName:%@, Familyname:%@", contact. GivenName, contact. Familyname);

//2. get phone, generics, will help a lot in the array of times

for (cnlabeledvalue *labeledvalue . Phonenumbers) {

NSLog(@ "label:%@", Labeledvalue. Label);

cnphonenumber *phonenumber = labeledvalue. Value;

NSLog(@ "PhoneNumber:%@", PhoneNumber. StringValue);

}

}

#pragma mark- This method enables you to Select multiple contacts that are triggered when you click the Done button, and note that this method is not affected by predicateforselectionofcontact Property Impact!

-(void) Contactpicker: (cncontactpickerviewcontroller *) Picker didselectcontacts: (Nsarray <cncontact *> *) contacts {

for (cncontact *contact in contacts) {

NSLog(@ "GivenName:%@, Familyname:%@", contact. GivenName, contact. Familyname);

//2. getting the phone, generics, would be a lot of help in array traversal

for (cnlabeledvalue *labeledvalue . Phonenumbers) {

NSLog(@ "label:%@", Labeledvalue. Label);

cnphonenumber *phonenumber = labeledvalue. Value;

NSLog(@ "PhoneNumber:%@", PhoneNumber. StringValue);

}

}

}

#pragma mark- triggers and returns the Contact property (Contactproperty) When you click on a property of a contact. When you implement this method only, you can go to the contact details page (if the Predicateforselectionofproperty property is not set or matches the filter criteria, if the non-conformance triggers the default action, call, email, etc.).

-(void) Contactpicker: (cncontactpickerviewcontroller *) Picker Didselectcontactproperty: ( Cncontactproperty *) contactproperty {

}

#pragma mark- when this method is implemented, the contact list page stays in multi-select mode (if the Predicateforselectionofproperty property is not set or matches the filter criteria, the contact is selected), click when the Done button is triggered, the returned contactproperties contains only the selected contactproperties, and returns empty if unchecked.

-(void) Contactpicker: (cncontactpickerviewcontroller *) Picker didselectcontactproperties: ( Nsarray<cncontactproperty *> *) contactproperties {

// loop to print out all selected contact names

for (cncontactproperty *contactproperty in contactproperties) {

NSLog(@ "%@", Contactproperty. Contact. GivenName);

}

}

Contacts-(IOS9 unique method)

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.