ios获得通讯录中联系人的所有属性
生活随笔
收集整理的這篇文章主要介紹了
ios获得通讯录中联系人的所有属性
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
ABAddressBookRef addressBook = ABAddressBookCreate();CFArrayRef results = ABAddressBookCopyArrayOfAllPeople(addressBook);for(int i = 0; i < CFArrayGetCount(results); i++){ABRecordRef person = CFArrayGetValueAtIndex(results, i);//讀取firstnameNSString *personName = (NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);if(personName != nil)textView.text = [textView.text stringByAppendingFormat:@"\n姓名:%@\n",personName];//讀取lastnameNSString *lastname = (NSString*)ABRecordCopyValue(person, kABPersonLastNameProperty);if(lastname != nil)textView.text = [textView.text stringByAppendingFormat:@"%@\n",lastname];//讀取middlenameNSString *middlename = (NSString*)ABRecordCopyValue(person, kABPersonMiddleNameProperty);if(middlename != nil)textView.text = [textView.text stringByAppendingFormat:@"%@\n",middlename];//讀取prefix前綴NSString *prefix = (NSString*)ABRecordCopyValue(person, kABPersonPrefixProperty);if(prefix != nil)textView.text = [textView.text stringByAppendingFormat:@"%@\n",prefix];//讀取suffix后綴NSString *suffix = (NSString*)ABRecordCopyValue(person, kABPersonSuffixProperty);if(suffix != nil)textView.text = [textView.text stringByAppendingFormat:@"%@\n",suffix];//讀取nickname呢稱NSString *nickname = (NSString*)ABRecordCopyValue(person, kABPersonNicknameProperty);if(nickname != nil)textView.text = [textView.text stringByAppendingFormat:@"%@\n",nickname];//讀取firstname拼音音標NSString *firstnamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonFirstNamePhoneticProperty);if(firstnamePhonetic != nil)textView.text = [textView.text stringByAppendingFormat:@"%@\n",firstnamePhonetic];//讀取lastname拼音音標NSString *lastnamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonLastNamePhoneticProperty);if(lastnamePhonetic != nil)
轉自iOS分享網 http://iosshare.cn
?
textView.text = [textView.text stringByAppendingFormat:@"%@\n",lastnamePhonetic];//讀取middlename拼音音標NSString *middlenamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonMiddleNamePhoneticProperty);if(middlenamePhonetic != nil)textView.text = [textView.text stringByAppendingFormat:@"%@\n",middlenamePhonetic];//讀取organization公司NSString *organization = (NSString*)ABRecordCopyValue(person, kABPersonOrganizationProperty);if(organization != nil)textView.text = [textView.text stringByAppendingFormat:@"%@\n",organization];//讀取jobtitle工作NSString *jobtitle = (NSString*)ABRecordCopyValue(person, kABPersonJobTitleProperty);if(jobtitle != nil)textView.text = [textView.text stringByAppendingFormat:@"%@\n",jobtitle];//讀取department部門NSString *department = (NSString*)ABRecordCopyValue(person, kABPersonDepartmentProperty);if(department != nil)textView.text = [textView.text stringByAppendingFormat:@"%@\n",department];//讀取birthday生日NSDate *birthday = (NSDate*)ABRecordCopyValue(person, kABPersonBirthdayProperty);if(birthday != nil)textView.text = [textView.text stringByAppendingFormat:@"%@\n",birthday];//讀取note備忘錄NSString *note = (NSString*)ABRecordCopyValue(person, kABPersonNoteProperty);if(note != nil)textView.text = [textView.text stringByAppendingFormat:@"%@\n",note];//第一次添加該條記錄的時間NSString *firstknow = (NSString*)ABRecordCopyValue(person, kABPersonCreationDateProperty);NSLog(@"第一次添加該條記錄的時間%@\n",firstknow);//最后一次修改該條記錄的時間NSString *lastknow = (NSString*)ABRecordCopyValue(person, kABPersonModificationDateProperty);NSLog(@"最后一次修改該條記錄的時間%@\n",lastknow);//獲取email多值ABMultiValueRef email = ABRecordCopyValue(person, kABPersonEmailProperty);int emailcount = ABMultiValueGetCount(email); for (int x = 0; x < emailcount; x++){//獲取email LabelNSString* emailLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(email, x));//獲取email值NSString* emailContent = (NSString*)ABMultiValueCopyValueAtIndex(email, x);textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",emailLabel,emailContent];}//讀取地址多值ABMultiValueRef address = ABRecordCopyValue(person, kABPersonAddressProperty);int count = ABMultiValueGetCount(address); for(int j = 0; j < count; j++){//獲取地址LabelNSString* addressLabel = (NSString*)ABMultiValueCopyLabelAtIndex(address, j);textView.text = [textView.text stringByAppendingFormat:@"%@\n",addressLabel];//獲取該label下的地址6屬性NSDictionary* personaddress =(NSDictionary*) ABMultiValueCopyValueAtIndex(address, j); NSString* country = [personaddress valueForKey:(NSString *)kABPersonAddressCountryKey];if(country != nil)textView.text = [textView.text stringByAppendingFormat:@"國家:%@\n",country];NSString* city = [personaddress valueForKey:(NSString *)kABPersonAddressCityKey];if(city != nil)textView.text = [textView.text stringByAppendingFormat:@"城市:%@\n",city];NSString* state = [personaddress valueForKey:(NSString *)kABPersonAddressStateKey];if(state != nil)textView.text = [textView.text stringByAppendingFormat:@"省:%@\n",state];NSString* street = [personaddress valueForKey:(NSString *)kABPersonAddressStreetKey];if(street != nil)textView.text = [textView.text stringByAppendingFormat:@"街道:%@\n",street];NSString* zip = [personaddress valueForKey:(NSString *)kABPersonAddressZIPKey];if(zip != nil)textView.text = [textView.text stringByAppendingFormat:@"郵編:%@\n",zip]; NSString* coutntrycode = [personaddress valueForKey:(NSString *)kABPersonAddressCountryCodeKey];if(coutntrycode != nil)textView.text = [textView.text stringByAppendingFormat:@"國家編號:%@\n",coutntrycode]; }//獲取dates多值ABMultiValueRef dates = ABRecordCopyValue(person, kABPersonDateProperty);int datescount = ABMultiValueGetCount(dates); for (int y = 0; y < datescount; y++){//獲取dates LabelNSString* datesLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(dates, y));//獲取dates值NSString* datesContent = (NSString*)ABMultiValueCopyValueAtIndex(dates, y);textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",datesLabel,datesContent];}//獲取kind值CFNumberRef recordType = ABRecordCopyValue(person, kABPersonKindProperty);if (recordType == kABPersonKindOrganization) {// it's a companyNSLog(@"it's a company\n");} else {// it's a person, resource, or roomNSLog(@"it's a person, resource, or room\n");}//獲取IM多值ABMultiValueRef instantMessage = ABRecordCopyValue(person, kABPersonInstantMessageProperty);for (int l = 1; l < ABMultiValueGetCount(instantMessage); l++){//獲取IM LabelNSString* instantMessageLabel = (NSString*)ABMultiValueCopyLabelAtIndex(instantMessage, l);textView.text = [textView.text stringByAppendingFormat:@"%@\n",instantMessageLabel];//獲取該label下的2屬性NSDictionary* instantMessageContent =(NSDictionary*) ABMultiValueCopyValueAtIndex(instantMessage, l); NSString* username = [instantMessageContent valueForKey:(NSString *)kABPersonInstantMessageUsernameKey];if(username != nil)textView.text = [textView.text stringByAppendingFormat:@"username:%@\n",username];NSString* service = [instantMessageContent valueForKey:(NSString *)kABPersonInstantMessageServiceKey];if(service != nil)textView.text = [textView.text stringByAppendingFormat:@"service:%@\n",service]; }//讀取電話多值ABMultiValueRef phone = ABRecordCopyValue(person, kABPersonPhoneProperty);for (int k = 0; k<ABMultiValueGetCount(phone); k++){//獲取電話LabelNSString * personPhoneLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(phone, k));//獲取該Label下的電話值NSString * personPhone = (NSString*)ABMultiValueCopyValueAtIndex(phone, k);textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",personPhoneLabel,personPhone];}//獲取URL多值ABMultiValueRef url = ABRecordCopyValue(person, kABPersonURLProperty);for (int m = 0; m < ABMultiValueGetCount(url); m++){//獲取電話LabelNSString * urlLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(url, m));//獲取該Label下的電話值NSString * urlContent = (NSString*)ABMultiValueCopyValueAtIndex(url,m);textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",urlLabel,urlContent];}//讀取照片NSData *image = (NSData*)ABPersonCopyImageData(person);UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(200, 0, 50, 50)];[myImage setImage:[UIImage imageWithData:image]];myImage.opaque = YES;[textView addSubview:myImage];}CFRelease(results);CFRelease(addressBook);轉自iOS分享網 http://iosshare.cn
轉載于:https://www.cnblogs.com/516inc/archive/2012/11/05/2755380.html
總結
以上是生活随笔為你收集整理的ios获得通讯录中联系人的所有属性的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android Wifi方法大全
- 下一篇: Maven搭建简单的SS项目