通讯录下载(恢复数据到手机上面)
来源:互联网 发布:字符串相似度匹配算法 编辑:程序博客网 时间:2024/04/29 16:59
遍历从webservice,服务器上面的json文件中数据
---解析json字符串---:
-(void)parseJsonKit:(NSString *)jsonString
{
NSArray *array=[jsonStringobjectFromJSONString];
NSLog(@"yunPanCounts=%d",[arraycount]);
//云端联系人的数量
self.yunpanCounts.text =[NSStringstringWithFormat:@"%u",[arraycount]];
for (int i =0; i< array.count; i++) {
NSDictionary* temp = [arrayobjectAtIndex:i];
NSString *firtname = [tempobjectForKey:@"firstname"];
NSString *lastname = [tempobjectForKey:@"lastname"];
NSString *middleName = [tempobjectForKey:@"middleName"];
NSString *prefix = [tempobjectForKey:@"prefix"];
NSString *suffix = [tempobjectForKey:@"suffix"];
NSString *firstnamePhonetic = [tempobjectForKey:@"firstnamePhonetic"];
NSString *lastnamePhonetic = [tempobjectForKey:@"lastnamePhonetic"];
NSString *organization = [tempobjectForKey:@"organization"];
NSString *jobtitle = [tempobjectForKey:@"jobtitle"];
NSString *department = [tempobjectForKey:@"department"];
NSString *note = [tempobjectForKey:@"note"];
NSString *birthday = [tempobjectForKey:@"birthday"];
NSString *firstKnow = [tempobjectForKey:@"firstKnow"];
NSString *lastKnow = [tempobjectForKey:@"lastKnow"];
//add to contact
ABAddressBookRef iphoneAddressBook =ABAddressBookCreate();
ABRecordRef newPerson =ABPersonCreate();
CFErrorRef error =NULL;
ABRecordSetValue(newPerson,kABPersonFirstNameProperty,firtname, &error);
ABRecordSetValue(newPerson,kABPersonLastNameProperty,lastname, &error);
ABRecordSetValue(newPerson,kABPersonMiddleNameProperty, middleName, &error);
ABRecordSetValue(newPerson,kABPersonPrefixProperty, prefix, &error);
ABRecordSetValue(newPerson,kABPersonSuffixProperty, suffix, &error);
ABRecordSetValue(newPerson,kABPersonFirstNamePhoneticProperty, firstnamePhonetic, &error);
ABRecordSetValue(newPerson,kABPersonLastNamePhoneticProperty, lastnamePhonetic, &error);
ABRecordSetValue(newPerson,kABPersonOrganizationProperty, organization, &error);
ABRecordSetValue(newPerson,kABPersonJobTitleProperty, jobtitle, &error);
ABRecordSetValue(newPerson,kABPersonDepartmentProperty, department, &error);
ABRecordSetValue(newPerson,kABPersonNoteProperty, note, &error);
ABRecordSetValue(newPerson,kABPersonBirthdayProperty, birthday, &error);
ABRecordSetValue(newPerson,kABPersonCreationDateProperty, firstKnow, &error);
ABRecordSetValue(newPerson,kABPersonModificationDateProperty, lastKnow, &error);
///////////////////特别值的注意的是多值字段的遍历///////////////////////////////
//用于存放具有多个值的项
ABMutableMultiValueRef multi =ABMultiValueCreateMutable(kABMultiStringPropertyType);
//得到多值字段[电话号码]的集合
NSMutableDictionary *phoneDict = [tempobjectForKey:@"phone"];
NSLog(@"%@",phoneDict);
for (id keyin phoneDict)
{
if ([keyisEqualToString:@"home"]) {
ABMultiValueAddValueAndLabel(multi, [phoneDict objectForKey:key], kABPersonHomePageLabel,NULL);
}
if ([keyisEqualToString:@"main"]) {
ABMultiValueAddValueAndLabel(multi, [phoneDict objectForKey:key], kABPersonPhoneMainLabel,NULL);
}
if ([keyisEqualToString:@"work fax"]) {
ABMultiValueAddValueAndLabel(multi, [phoneDict objectForKey:key], kABPersonPhoneWorkFAXLabel,NULL);
}
//other
if ([keyisEqualToString:@"mobile"]) {
ABMultiValueAddValueAndLabel(multi, [phoneDict objectForKey:key], kABPersonPhoneMobileLabel,NULL);
}
if ([keyisEqualToString:@"home fax"]) {
ABMultiValueAddValueAndLabel(multi, [phoneDict objectForKey:key], kABPersonPhoneHomeFAXLabel,NULL);
}
if ([keyisEqualToString:@"other fax"]) {
ABMultiValueAddValueAndLabel(multi, [phoneDict objectForKey:key], kABPersonPhoneOtherFAXLabel,NULL);
}
if ([keyisEqualToString:@"pager"]) {
ABMultiValueAddValueAndLabel(multi, [phoneDict objectForKey:key], kABPersonPhonePagerLabel,NULL);
}
if ([keyisEqualToString:@"iPhone"]) {
ABMultiValueAddValueAndLabel(multi, [phoneDict objectForKey:key], kABPersonPhoneIPhoneLabel,NULL);
}
ABRecordSetValue(newPerson,kABPersonPhoneProperty, multi, &error);
}
//清空该变量用于存放下一个多值的项
multi = nil;
////////////////////////////////////////////////////////////////////////////////
ABAddressBookAddRecord(iphoneAddressBook, newPerson, &error);
ABAddressBookSave(iphoneAddressBook, &error);
if (error!=NULL) {
NSLog(@"Danger will Robinson! Danger!!!");
}
CFRelease(newPerson);
CFRelease(iphoneAddressBook);
}
}
- 通讯录下载(恢复数据到手机上面)
- 手机通讯录数据怎么恢复
- 手机通讯录数据丢失怎么恢复
- 手机通讯录恢复
- 手机通讯录乱码怎么恢复
- iPhone手机通讯录恢复方法
- 获取手机通讯录-----1.1(取出通讯录数据)
- 通讯录的内容提供者(查询手机通讯录的数据)
- 手机数据恢复精灵教你快速找回误删除的手机通讯录
- 苹果(iphone)手机怎么恢复手机通讯录
- 手机通讯录、联系人的备份、恢复经验
- 手机通讯录被删除后还能恢复吗
- 手机通讯录变成乱码如何恢复
- 手机通讯录被删除后怎么恢复
- 手机通讯录误删怎么恢复
- android手机误删通讯录恢复
- 手机通讯录增删改查(在ListView上面操作),复杂
- 三星系列手机点错键恢复出厂了如何恢复通讯录
- 判断WinCE的版本
- Oracle中时间处理及分时间段统计
- LOL英雄联盟,新人最值得玩的英雄
- 养颜补血使你更健康
- Tomcat 内存溢出
- 通讯录下载(恢复数据到手机上面)
- WINCE重新启动
- windows+ubuntu双系统以及ubuntu下面oracle安装
- 解析IPV4报文 和IPV6 报文的 checksum
- Unparsed aapt error(s)! Check the console for output解决方法
- HTML中UL、OL、LI的用法
- linux创建用户命令
- 【程序员一枚】C++基础之内存对齐
- WINCE6.0添加特定的软件键盘