IOS Address Book-write information

Source: Internet
Author: User

IOS Address Book-write information

I wrote basic knowledge and the address book query function. Now let's take a look at writing information.

Create modify Delete
# Pragma mark-write contact information // create a contact-(void) creatNewRecord {CFErrorRef error = NULL; // create an address book operation object ABAddressBookRef addressBook = abaddressbookcreatewitexceptions (NULL, & error ); // create a new contact record ABRecordRef newRecord = ABPersonCreate (); // Add the attribute value ABRecordSetValue (newRecord, kABPersonFirstNameProperty, (_ bridge CFTypeRef) @ "cedar ", & error); // create a multi-value attribute ABMutableMultiValueRef multi = ABMultiValueCreateMutable (kABMultiStringPropertyType); assign (multi, (_ bridge CFTypeRef) @ "12345678990", kabpersonphonecancelabel, NULL ); increment (multi, (_ bridge CFTypeRef) @ "11234567890", kABPersonPhoneIPhoneLabel, NULL); // Add the multi-value attribute to the record ABRecordSetValue (newRecord, kABPersonPhoneProperty, multi, & error ); CFRelease (multi); // Add a record to the address book operation object ABAddressBookAddRecord (addressBook, newRecord, & error); // Save the address book operation object ABAddressBookSave (addressBook, & error ); CFRelease (newRecord); CFRelease (addressBook);}-(void) editRecord {CFErrorRef error = NULL; ABAddressBookRef addressBook = abaddressbookcreatewitexceptions (NULL, & error ); ABRecordID recordID = [personIDASNumber intValue]; ABRecordRef record = Alibaba (addressBook, recordID); // set the phone number ABMutableMultiValueRef multi = Alibaba (kABMultiStringPropertyType); multiple (multi, (_ bridge CFTypeRef) @ "12345678900", kabpersonphonecancelabel, NULL); ABMultiValueAddValueAndLabel (multi, (_ bridge CFTypeRef) @ "12345678900", kABPersonPhoneIPhoneLabel, NULL ); // Add the phone number to the database ABRecordSetValue (record, kABPersonPhoneProperty, multi, & error); CFRelease (multi); // save it to the database ABAddressBookSave (addressBook, & error ); CFRelease (addressBook);}-(void) deleteRecord {CFErrorRef error = NULL; ABAddressBookRef addressBook = empty (NULL, & error); ABRecordID recordID = [personIDASNumber intValue]; ABRecordRef record = addressBook, recordID); // Delete the ABAddressBookRemoveRecord (addressBook, record, & error); // save it to the database ABAddressBookSave (addressBook, & error ); CFRelease (addressBook );}


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.