iOS 通訊錄--寫入資訊

來源:互聯網
上載者:User

標籤:ios   通訊錄   

寫了基礎知識和查詢通訊錄的功能了現在我們來看一下寫入資訊

  • 建立
  • 修改
  • 刪除
#pragma mark  - 寫入連絡人資訊//建立連絡人- (void) creatNewRecord{    CFErrorRef error = NULL;        //建立一個通訊錄操作對象    ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &error);        //建立一條新的連絡人紀錄    ABRecordRef newRecord = ABPersonCreate();        //為新連絡人記錄添加屬性值    ABRecordSetValue(newRecord, kABPersonFirstNameProperty, (__bridge CFTypeRef)@"雪松", &error);        //建立一個多值屬性    ABMutableMultiValueRef multi = ABMultiValueCreateMutable(kABMultiStringPropertyType);    ABMultiValueAddValueAndLabel(multi, (__bridge CFTypeRef)@"12345678990", kABPersonPhoneMobileLabel, NULL);    ABMultiValueAddValueAndLabel(multi, (__bridge CFTypeRef)@"11234567890", kABPersonPhoneIPhoneLabel, NULL);        //將多值屬性添加到記錄    ABRecordSetValue(newRecord, kABPersonPhoneProperty, multi, &error);    CFRelease(multi);        //添加記錄到通訊錄操作對象    ABAddressBookAddRecord(addressBook, newRecord, &error);        //儲存通訊錄操作對象    ABAddressBookSave(addressBook, &error);    CFRelease(newRecord);    CFRelease(addressBook);}- (void) editRecord{    CFErrorRef error = NULL;    ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &error);    ABRecordID recordID = [personIDASNumber intValue];    ABRecordRef record = ABAddressBookGetPersonWithRecordID(addressBook, recordID);        //設定電話號碼    ABMutableMultiValueRef multi = ABMultiValueCreateMutable(kABMultiStringPropertyType);    ABMultiValueAddValueAndLabel(multi, (__bridge CFTypeRef)@"12345678900", kABPersonPhoneMobileLabel, NULL);    ABMultiValueAddValueAndLabel(multi, (__bridge CFTypeRef)@"12345678900", kABPersonPhoneIPhoneLabel, NULL);        //添加電話號碼到資料庫    ABRecordSetValue(record, kABPersonPhoneProperty, multi, &error);    CFRelease(multi);        //儲存到資料庫    ABAddressBookSave(addressBook, &error);    CFRelease(addressBook);    }- (void)deleteRecord{    CFErrorRef error = NULL;    ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &error);    ABRecordID recordID = [personIDASNumber intValue];    ABRecordRef record = ABAddressBookGetPersonWithRecordID(addressBook, recordID);        //刪除記錄    ABAddressBookRemoveRecord(addressBook, record, &error);        //儲存到資料庫    ABAddressBookSave(addressBook, &error);    CFRelease(addressBook);}


iOS 通訊錄--寫入資訊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.