博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
通过代码创建联系人
阅读量:4507 次
发布时间:2019-06-08

本文共 2368 字,大约阅读时间需要 7 分钟。

首先,需要导入AddressBook.framework框架,然后在头文件中加入:#import <AddressBook/AddressBook.h>

 

 

Ios代码  
CFErrorRef error = NULL;          ABAddressBookRef addressBook = ABAddressBookCreate();         ABRecordRef newPerson= ABPersonCreate();     ABRecordSetValue(newPerson, kABPersonFirstNameProperty, @"Eric", &error);         ABRecordSetValue(newPerson, kABPersonLastNameProperty, @"Gao", &error);               ABRecordSetValue(newPerson, kABPersonJobTitleProperty, @"市场部经理", &error);  ABRecordSetValue(newPerson, kABPersonOrganizationProperty, @"移动技术研发", &error);    ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);            ABMultiValueAddValueAndLabel(multiPhone, @"12345678", kABPersonPhoneMainLabel, NULL);                         ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiPhone, &error);              CFRelease(multiPhone);    ABMutableMultiValueRef multiEmail = ABMultiValueCreateMutable(kABMultiStringPropertyType);  ABMultiValueAddValueAndLabel(multiEmail, @"别墅", kABHomeLabel, NULL);  ABRecordSetValue(newPerson, kABPersonEmailProperty, multiEmail, &error);  CFRelease(multiEmail);    ABMutableMultiValueRef urlMultiValue = ABMultiValueCreateMutable(kABMultiStringPropertyType);  ABMultiValueAddValueAndLabel(urlMultiValue,@"www.google.cn", kABPersonHomePageLabel, NULL);  ABRecordSetValue(newPerson, kABPersonURLProperty, urlMultiValue, &error);  CFRelease(urlMultiValue);    ABMutableMultiValueRef multiAddress = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);  NSMutableDictionary *addressDictionary = [[NSMutableDictionary alloc] init];  [addressDictionary setObject:@"北京市海淀区中关村" forKey:(NSString *) kABPersonAddressStreetKey];  ABMultiValueAddValueAndLabel(multiAddress, addressDictionary, kABWorkLabel, NULL);  ABRecordSetValue(newPerson, kABPersonAddressProperty, multiAddress, &error);  CFRelease(multiAddress);    UIImage *image = [UIImage imageNamed:@"head.png"];    if (image) {      NSData *dataRef = UIImagePNGRepresentation(image);       CFDataRef dr = CFDataCreate(NULL, [dataRef bytes], [dataRef length]);      ABPersonSetImageData(newPerson, dr, &error);      CFRelease(dr);                }       ABAddressBookAddRecord(addressBook, newPerson, &error);   CFRelease(newPerson);    ABAddressBookSave(addressBook, &error);

效果图:

转载于:https://www.cnblogs.com/zlja/archive/2012/04/12/2444799.html

你可能感兴趣的文章
python接口自动化测试二十五:执行所有用例,并生成HTML测试报告
查看>>
Docker 安装及问题处理
查看>>
正则表达式之 数据验证 与 文本替换
查看>>
linux 安装mysql数据库——yum安装法
查看>>
Visual Studio 2008 不能更改安装目录的原因
查看>>
关于求最大公约数
查看>>
为Linux配置常用源:epel和IUS
查看>>
天府地
查看>>
C#高级编程
查看>>
JS实现从照片中裁切自已的肖像
查看>>
使用 https://git.io 缩短 a GitHub.com URL.
查看>>
拷贝、浅拷贝、深拷贝解答
查看>>
四元数
查看>>
StackAndQueue(栈与队列)
查看>>
URLOS安装、升级、卸载
查看>>
在win7下配置sql2005允许远程访问
查看>>
aspose.cell 设置excel里面的文字是超链接
查看>>
POJ 1067 取石子游戏
查看>>
django开发框架-view & template
查看>>
[Linux]systemd和sysV
查看>>