gpt4 book ai didi

iphone - 如何向 iOS 通讯录(地址簿)添加新联系人?

转载 作者:行者123 更新时间:2023-12-03 18:26:40 26 4
gpt4 key购买 nike

我想以编程方式将联系人直接保存到 iOS 设备的地址簿。

我该怎么做?

最佳答案

这是一个小例子:

CFErrorRef error = NULL; 
NSLog(@"%@", [self description]);
ABAddressBookRef iPhoneAddressBook = ABAddressBookCreate();

ABRecordRef newPerson = ABPersonCreate();

ABRecordSetValue(newPerson, kABPersonFirstNameProperty, people.firstname, &error);
ABRecordSetValue(newPerson, kABPersonLastNameProperty, people.lastname, &error);

ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiPhone, people.phone, kABPersonPhoneMainLabel, NULL);
ABMultiValueAddValueAndLabel(multiPhone, people.other, kABOtherLabel, NULL);
ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiPhone,nil);
CFRelease(multiPhone);
// ...
// Set other properties
// ...
ABAddressBookAddRecord(iPhoneAddressBook, newPerson, &error);

ABAddressBookSave(iPhoneAddressBook, &error);
CFRelease(newPerson);
CFRelease(iPhoneAddressBook);
if (error != NULL)
{
CFStringRef errorDesc = CFErrorCopyDescription(error);
NSLog(@"Contact not saved: %@", errorDesc);
CFRelease(errorDesc);
}

关于iphone - 如何向 iOS 通讯录(地址簿)添加新联系人?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5389508/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com