IOS learning and ios development

Source: Internet
Author: User

IOS learning and ios development

In the IOS 9 SDK, Apple abolished some of the AddressBookUI. framework Functions (whether the library has been abolished and needs to be verified). The specific system interfaces related to saving contacts are as follows:
Contact Selection: AddressBookUI/abw.lepickernavigationcontroller. h
Contact details: AddressBookUI/ABPersonViewController. h
Unknown contact: AddressBookUI/ABUnknownPersonViewController. h
Create a contact: AddressBookUI/ABNewPersonViewController. h
Use in the new SDK
Contact: ContactsUI/CNContactPickerViewController. h
Contact details, new contacts, and unknown contacts: ContactsUI/CNContactViewController. h (create using different methods, as described below)

In the following example, the problem persists.

1. The title of UINavgationController and the Left and Right items are all built-in by the system. When the contact details are met, the return button of navgationItem does not have a click event. How can this problem be customized?

2. The contact logo is black screen (the real machine test has obtained the permission ).

# Import "ViewController. h "# import <ContactsUI/CNContactPickerViewController. h> # import <ContactsUI/CNContactViewController. h> @ interface ViewController () <CNContactViewControllerDelegate, CNContactPickerDelegate> @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad];}-(IBAction) Click :( id) sender {[self set1];} // Save the new contact-(void) set {// 1. create a Contact object, which must be a variable CNMutableContact * contact = [[CNMutableContact alloc] init]; // 2. assign a value to contact [self setValue4Contact: contact existContect: NO]; // 3. create a new friend page CNContactViewController * controller = [CNContactViewController viewControllerForNewContact: contact]; controller. delegate = self; UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController: controller]; [self presentViewController: nav animated: YES completion: n Il];} // Save the existing contact-(void) set1 {// jump to the contact selection page. Note that UINavgationController CNContactPickerViewController * picker = [[CNContactPickerViewController alloc] init] is not used here; picker. delegate = self; [self presentViewController: picker animated: YES completion: nil];} // click the proxy to implement other proxy methods as needed-(void) contactPicker :( CNContactPickerViewController *) picker didSelectContact :( CNContact *) contact {[picker dismissViewControllerAn Imated: YES completion: ^ {// copy a writable contact object. Do not try alloc. mutableCopy is the only CNMutableContact * c = [contact mutableCopy]. // assign a value to contact [self setValue4Contact: c existContect: YES]; // jump to the CNContactViewController * controller = [CNContactViewController viewControllerForNewContact: c]; controller on the new contact page. delegate = self; UINavigationController * nav = [[UINavigationController alloc] initWithRootViewCo Ntroller: controller]; [self presentViewController: nav animated: YES completion: nil];}] ;}// set the contact object to be saved-(void) setValue4Contact :( CNMutableContact *) contact existContect :( BOOL) exist {if (! Exist) {// name and profile contact. 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 {// current 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: @" "]; // Email: CNLabeledValue * mail = [CNLabeledValue labeledValueWithLabel: CNLabelWork value: self. poiData4Save. mail]; // a special address. PostalAddress corresponds to the address CNMutablePostalAddress * address = [[CNMutablePostalAddress alloc] init]; address. state = @ "Jiangsu Province"; address. city = @ "Nanjing"; address. postalCode = @ "20000"; address. street = @ "No. 18, wangba street, Xinjiekou"; // The CNLabeledValue generated above. You can set CNLabelWork and other cnlabeledvalues * addressLabe. L = [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] ;}}

 

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.