首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

iPhone开发—获得通讯录中联系人的所有属性

iPhone开发—获得通讯录中联系人的所有属性

iPhone开发—获得通讯录中联系人的所有属性
  
  ABAddressBookRefaddressBook=ABAddressBookCreate();CFArrayRefresults=ABAddressBookCopyArrayOfAllPeople(addressBook);for(inti=0;i<CFArrayGetCount(results);i++){ABRecordRefperson=CFArrayGetValueAtIndex(results,i);//读取firstnameNSString*personName=(NSString*)ABRecordCopyValue(person,kABPersonFirstNameProperty);if(personName!=nil)textView.text=[textView.textstringByAppendingFormat"\n姓名:%@\n",personName];//读取lastnameNSString*lastname=(NSString*)ABRecordCopyValue(person,kABPersonLastNameProperty);if(lastname!=nil)textView.text=[textView.textstringByAppendingFormat"%@\n",lastname];//读取middlenameNSString*middlename=(NSString*)ABRecordCopyValue(person,kABPersonMiddleNameProperty);if(middlename!=nil)textView.text=[textView.textstringByAppendingFormat"%@\n",middlename];//读取prefix前缀NSString*prefix=(NSString*)ABRecordCopyValue(person,kABPersonPrefixProperty);if(prefix!=nil)textView.text=[textView.textstringByAppendingFormat"%@\n",prefix];//读取suffix后缀NSString*suffix=(NSString*)ABRecordCopyValue(person,kABPersonSuffixProperty);if(suffix!=nil)textView.text=[textView.textstringByAppendingFormat"%@\n",suffix];//读取nickname呢称NSString*nickname=(NSString*)ABRecordCopyValue(person,kABPersonNicknameProperty);if(nickname!=nil)textView.text=[textView.textstringByAppendingFormat"%@\n",nickname];//读取firstname拼音音标NSString*firstnamePhonetic=(NSString*)ABRecordCopyValue(person,kABPersonFirstNamePhoneticProperty);if(firstnamePhonetic!=nil)textView.text=[textView.textstringByAppendingFormat"%@\n",firstnamePhonetic];//读取lastname拼音音标NSString*lastnamePhonetic=(NSString*)ABRecordCopyValue(person,kABPersonLastNamePhoneticProperty);if(lastnamePhonetic!=nil)textView.text=[textView.textstringByAppendingFormat"%@\n",lastnamePhonetic];//读取middlename拼音音标NSString*middlenamePhonetic=(NSString*)ABRecordCopyValue(person,kABPersonMiddleNamePhoneticProperty);if(middlenamePhonetic!=nil)textView.text=[textView.textstringByAppendingFormat"%@\n",middlenamePhonetic];//读取organization公司NSString*organization=(NSString*)ABRecordCopyValue(person,kABPersonOrganizationProperty);if(organization!=nil)textView.text=[textView.textstringByAppendingFormat"%@\n",organization];//读取jobtitle工作NSString*jobtitle=(NSString*)ABRecordCopyValue(person,kABPersonJobTitleProperty);if(jobtitle!=nil)textView.text=[textView.textstringByAppendingFormat:@"%@\n",jobtitle];//读取department部门NSString*department=(NSString*)ABRecordCopyValue(person,kABPersonDepartmentProperty);if(department!=nil)textView.text=[textView.textstringByAppendingFormat:@"%@\n",department];//读取birthday生日NSDate*birthday=(NSDate*)ABRecordCopyValue(person,kABPersonBirthdayProperty);if(birthday!=nil)textView.text=[textView.textstringByAppendingFormat:@"%@\n",birthday];//读取note备忘录NSString*note=(NSString*)ABRecordCopyValue(person,kABPersonNoteProperty);if(note!=nil)textView.text=[textView.textstringByAppendingFormat:@"%@\n",note];//第一次添加该条记录的时间NSString*firstknow=(NSString*)ABRecordCopyValue(person,kABPersonCreationDateProperty);NSLog(@"第一次添加该条记录的时间%@\n",firstknow);//最后一次修改該条记录的时间NSString*lastknow=(NSString*)ABRecordCopyValue(person,kABPersonModificationDateProperty);NSLog(@"最后一次修改該条记录的时间%@\n",lastknow);//获取email多值ABMultiValueRefemail=ABRecordCopyValue(person,kABPersonEmailProperty);intemailcount=ABMultiValueGetCount(email);for(intx=0;x<emailcount;x++){//获取emailLabelNSString*emailLabel=(NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(email,x));//获取email值NSString*emailContent=(NSString*)ABMultiValueCopyValueAtIndex(email,x);textView.text=[textView.textstringByAppendingFormat:@"%@:%@\n",emailLabel,emailContent];}//读取地址多值ABMultiValueRefaddress=ABRecordCopyValue(person,kABPersonAddressProperty);intcount=ABMultiValueGetCount(address);for(intj=0;j<count;j++){//获取地址LabelNSString*addressLabel=(NSString*)ABMultiValueCopyLabelAtIndex(address,j);textView.text=[textView.textstringByAppendingFormat:@"%@\n",addressLabel];//获取該label下的地址6属性NSDictionary*personaddress=(NSDictionary*)ABMultiValueCopyValueAtIndex(address,j);NSString*country=[personaddressvalueForKeyNSString*)kABPersonAddressCountryKey];if(country!=nil)textView.text=[textView.textstringByAppendingFormat:@"国家:%@\n",country];NSString*city=[personaddressvalueForKeyNSString*)kABPersonAddressCityKey];if(city!=nil)textView.text=[textView.textstringByAppendingFormat:@"城市:%@\n",city];NSString*state=[personaddressvalueForKeyNSString*)kABPersonAddressStateKey];if(state!=nil)textView.text=[textView.textstringByAppendingFormat:@"省:%@\n",state];NSString*street=[personaddressvalueForKeyNSString*)kABPersonAddressStreetKey];if(street!=nil)textView.text=[textView.textstringByAppendingFormat:@"街道:%@\n",street];NSString*zip=[personaddressvalueForKeyNSString*)kABPersonAddressZIPKey];if(zip!=nil)textView.text=[textView.textstringByAppendingFormat:@"邮编:%@\n",zip];NSString*coutntrycode=[personaddressvalueForKeyNSString*)kABPersonAddressCountryCodeKey];if(coutntrycode!=nil)textView.text=[textView.textstringByAppendingFormat:@"国家编号:%@\n",coutntrycode];}//获取dates多值ABMultiValueRefdates=ABRecordCopyValue(person,kABPersonDateProperty);intdatescount=ABMultiValueGetCount(dates);for(inty=0;y<datescount;y++){//获取datesLabelNSString*datesLabel=(NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(dates,y));//获取dates值NSString*datesContent=(NSString*)ABMultiValueCopyValueAtIndex(dates,y);textView.text=[textView.textstringByAppendingFormat:@"%@:%@\n",datesLabel,datesContent];}//获取kind值CFNumberRefrecordType=ABRecordCopyValue(person,kABPersonKindProperty);if(recordType==kABPersonKindOrganization){//it'sacompanyNSLog(@"it'sacompany\n");}else{//it'saperson,resource,orroomNSLog(@"it'saperson,resource,orroom\n");}//获取IM多值ABMultiValueRefinstantMessage=ABRecordCopyValue(person,kABPersonInstantMessageProperty);for(intl=1;l<ABMultiValueGetCount(instantMessage);l++){//获取IMLabelNSString*instantMessageLabel=(NSString*)ABMultiValueCopyLabelAtIndex(instantMessage,l);textView.text=[textView.textstringByAppendingFormat:@"%@\n",instantMessageLabel];//获取該label下的2属性NSDictionary*instantMessageContent=(NSDictionary*)ABMultiValueCopyValueAtIndex(instantMessage,l);NSString*username=[instantMessageContentvalueForKeyNSString*)kABPersonInstantMessageUsernameKey];if(username!=nil)textView.text=[textView.textstringByAppendingFormat:@"username:%@\n",username];NSString*service=[instantMessageContentvalueForKeyNSString*)kABPersonInstantMessageServiceKey];if(service!=nil)textView.text=[textView.textstringByAppendingFormat:@"service:%@\n",service];}//读取电话多值ABMultiValueRefphone=ABRecordCopyValue(person,kABPersonPhoneProperty);for(intk=0;k<ABMultiValueGetCount(phone);k++){//获取电话LabelNSString*personPhoneLabel=(NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(phone,k));//获取該Label下的电话值NSString*personPhone=(NSString*)ABMultiValueCopyValueAtIndex(phone,k);textView.text=[textView.textstringByAppendingFormat:@"%@:%@\n",personPhoneLabel,personPhone];}//获取URL多值ABMultiValueRefurl=ABRecordCopyValue(person,kABPersonURLProperty);for(intm=0;m<ABMultiValueGetCount(url);m++){//获取电话LabelNSString*urlLabel=(NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(url,m));//获取該Label下的电话值NSString*urlContent=(NSString*)ABMultiValueCopyValueAtIndex(url,m);textView.text=[textView.textstringByAppendingFormat:@"%@:%@\n",urlLabel,urlContent];}//读取照片NSData*image=(NSData*)ABPersonCopyImageData(person);UIImageView*myImage=[[UIImageViewalloc]initWithFrame:CGRectMake(200,0,50,50)];[myImagesetImage:[UIImageimageWithData:image]];myImage.opaque=YES;[textViewaddSubview:myImage];}CFRelease(results);CFRelease(addressBook);
  
  官方网站:http://www.3gtrain.com/
  
  联系地址:河南.郑州.金水区.经三路65号江山商界A座615室【经三路农科路交叉口南50米路东】
  
  联系电话:0371-86189958
  
  联系传真:0371-86189978
  
  免费电话:4000-159-369
  
  官方QQ:130159369
  
  官方邮箱:3g@3gtrain.com
  
http://www.3gtrain.com/index.asp
返回列表