iOS learning-14. Local Contacts

Source: Internet
Author: User

Apple has abolished some of the features of Addressbookui.framework in the IOS9 SDK (whether the library has been abolished, yet to be verified), and several system interfaces related to saving contacts are as follows:
Contact Selection: Addressbookui/abpeoplepickernavigationcontroller.h
Contact Details: addressbookui/abpersonviewcontroller.h
Unknown Contact: addressbookui/abunknownpersonviewcontroller.h
New Contact: Addressbookui/abnewpersonviewcontroller.h
Used in the new SDK
Contact Selection: Contactsui/cncontactpickerviewcontroller.h
Contact details, new contact, unknown Contact: Contactsui/cncontactviewcontroller.h (created using a different method, as described below)

In the following example, there are still problems

1.UINavgationController title, left and right item are the system comes with, contact details, when the Navgationitem return button No click event, how should be customized?

2. Contact person logo Photo black screen (real machine test has been acquired), to be resolved

#import "ViewController.h"#import<ContactsUI/CNContactPickerViewController.h>#import<ContactsUI/CNContactViewController.h>@interfaceViewcontroller () <CNContactViewControllerDelegate,CNContactPickerDelegate>@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload];}-(Ibaction) Click: (IDsender {[self set1];}//Save new contacts-(void)Set{    //1. Create contact object, must be variableCnmutablecontact *contact =[[Cnmutablecontact alloc]init]; //2. Assigning a value to the contact[self setvalue4contact:contact existcontect:no]; //3. Create a new friend pageCncontactviewcontroller *controller =[Cncontactviewcontroller viewcontrollerfornewcontact:contact]; Controller.Delegate=Self ; Uinavigationcontroller*nav =[[Uinavigationcontroller Alloc]initwithrootviewcontroller:controller]; [Self Presentviewcontroller:nav animated:yes completion:nil];}//save an existing contact-(void) set1{//Jump to the Contact selection page, note that there is no use of UinavgationcontrollerCncontactpickerviewcontroller *picker =[[Cncontactpickerviewcontroller alloc]init]; Picker.Delegate=Self ; [Self Presentviewcontroller:picker animated:yes completion:nil];}//implement the agent of the point selection, other proxy methods to implement according to their own needs-(void) Contactpicker: (Cncontactpickerviewcontroller *) Picker didselectcontact: (Cncontact *) contact{[picker dismissviewcontrolleranimated:yes Completion:^{    //copy a writable contact object, do not try Alloc class, mutablecopy alone this oneCnmutablecontact *c =[Contact Mutablecopy]; //assign a value to the contact[self setvalue4contact:c existcontect:yes]; //Jump to new contact pageCncontactviewcontroller *controller =[Cncontactviewcontroller Viewcontrollerfornewcontact:c]; Controller.Delegate=Self ; Uinavigationcontroller*nav =[[Uinavigationcontroller Alloc]initwithrootviewcontroller:controller];    [Self Presentviewcontroller:nav animated:yes completion:nil]; }];}//set the Contact object to save- (void) Setvalue4contact: (Cnmutablecontact *) Contact Existcontect: (BOOL) exist{if(!exist) {        //Name and AvatarContact.nickname =@"Oriccheng"; /*UIImage *logo = [UIImage imagenamed:@ ""];         NSData *dataref = uiimagepngrepresentation (logo);                  Contact.imagedata = Dataref; */} cnlabeledvalue*phonenumber = [Cnlabeledvalue labeledvaluewithlabel:cnlabelphonenumbermobile value:[cnphonenumber Phonenumberwithstringvalue:@"18888888888"]]; if(!exist) {Contact.phonenumbers=@[phonenumber]; }Else{        //Existing Contact information        if([Contact.phonenumbers Count] >0) {Nsmutablearray*phonenumbers =[[Nsmutablearray alloc]initwitharray:contact.phonenumbers];            [Phonenumbers Addobject:phonenumber]; Contact.phonenumbers=phonenumbers; }Else{contact.phonenumbers=@[phonenumber]; }    }    //URL: Cnlabeledvalue *url = [Cnlabeledvalue labeledvaluewithlabel:@ "" value:@ "]; //e-mail: Cnlabeledvalue *mail = [Cnlabeledvalue labeledvaluewithlabel:cnlabelwork value:self.poiData4Save.mail]; //specifically, an address, postaladdress corresponds to the addressCnmutablepostaladdress *address =[[Cnmutablepostaladdress alloc]init]; Address.state=@"Jiangsu Province"; Address.city=@"Nanjing"; Address.postalcode=@"20000"; Address.street=@"No. 18th, Xinjiekou Wang eight street"; //generated above up to the Cnlabeledvalue, where you can set type Cnlabelwork and so onCnlabeledvalue *addresslabel =[Cnlabeledvalue labeledvaluewithlabel:cnlabelwork value:address]; if(!exist) {contact.postaladdresses=@[addresslabel]; }Else{        if(Contact.postalAddresses.count >0) {Nsmutablearray*addresses =[[Nsmutablearray alloc]initwitharray:contact.postaladdresses];            [Addresses Addobject:addresslabel]; Contact.postaladdresses=addresses; }Else{contact.postaladdresses=@[addresslabel]; }    }    }

iOS learning-14. Local Contacts

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.