ios如何實(shí)現(xiàn)通訊錄聯(lián)系人各屬性獲取-創(chuàng)新互聯(lián)

這篇文章主要介紹了ios如何實(shí)現(xiàn)通訊錄聯(lián)系人各屬性獲取,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

成都地區(qū)優(yōu)秀IDC服務(wù)器托管提供商(創(chuàng)新互聯(lián)).為客戶提供專業(yè)的雅安機(jī)房托管,四川各地服務(wù)器托管,雅安機(jī)房托管、多線服務(wù)器托管.托管咨詢專線:18982081108

ABAddressBookRef addressBook = ABAddressBookCreate();

   CFArrayRef results = ABAddressBookCopyArrayOfAllPeople(addressBook);

   for(int i = 0; i < CFArrayGetCount(results); i++)

  {

     ABRecordRef person = CFArrayGetValueAtIndex(results, i);

     //讀取firstname

     NSString *personName = (NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);

     if(personName != nil)

       label.text = [label.text stringByAppendingFormat:@"姓名:%@",personName];

     //讀取lastname

     NSString *lastname = (NSString*)ABRecordCopyValue(person, kABPersonLastNameProperty);

     if(lastname != nil)

       label.text = [label.text stringByAppendingFormat:@"%@",lastname];

     //讀取middlename

     NSString *middlename = (NSString*)ABRecordCopyValue(person, kABPersonMiddleNameProperty);

     if(middlename != nil)

       label.text = [label.text stringByAppendingFormat:@"%@",middlename];

     //讀取prefix前綴

     NSString *prefix = (NSString*)ABRecordCopyValue(person, kABPersonPrefixProperty);

     if(prefix != nil)

       label.text = [label.text stringByAppendingFormat:@"%@",prefix];

     //讀取suffix后綴

     NSString *suffix = (NSString*)ABRecordCopyValue(person, kABPersonSuffixProperty);

     if(suffix != nil)

       label.text = [label.text stringByAppendingFormat:@"%@",suffix];

     //讀取nickname呢稱

     NSString *nickname = (NSString*)ABRecordCopyValue(person, kABPersonNicknameProperty);

     if(nickname != nil)

       label.text = [label.text stringByAppendingFormat:@"%@",nickname];

     //讀取firstname拼音音標(biāo)

     NSString *firstnamePhonetic = (NSString*)ABRecordCopyValue(person,kABPersonFirstNamePhoneticProperty);

     if(firstnamePhonetic != nil)

       label.text = [label.text stringByAppendingFormat:@"%@",firstnamePhonetic];

     //讀取lastname拼音音標(biāo)

     NSString *lastnamePhonetic = (NSString*)ABRecordCopyValue(person,kABPersonLastNamePhoneticProperty);

     if(lastnamePhonetic != nil)

       label.text = [label.text stringByAppendingFormat:@"%@",lastnamePhonetic];

     //讀取middlename拼音音標(biāo)

     NSString *middlenamePhonetic = (NSString*)ABRecordCopyValue(person,kABPersonMiddleNamePhoneticProperty);

     if(middlenamePhonetic != nil)

       label.text = [label.text stringByAppendingFormat:@"%@",middlenamePhonetic];

     //讀取organization公司

     NSString *organization = (NSString*)ABRecordCopyValue(person, kABPersonOrganizationProperty);

     if(organization != nil)

       label.text = [label.text stringByAppendingFormat:@"%@",organization];

     //讀取jobtitle工作

     NSString *jobtitle = (NSString*)ABRecordCopyValue(person, kABPersonJobTitleProperty);

     if(jobtitle != nil)

       label.text = [label.text stringByAppendingFormat:@"%@",jobtitle];

     //讀取department部門

     NSString *department = (NSString*)ABRecordCopyValue(person, kABPersonDepartmentProperty);

     if(department != nil)

       label.text = [label.text stringByAppendingFormat:@"%@",department];

     //讀取birthday生日

     NSDate *birthday = (NSDate*)ABRecordCopyValue(person, kABPersonBirthdayProperty);

     if(birthday != nil)

       label.text = [label.text stringByAppendingFormat:@"%@",birthday];

     //讀取note備忘錄

     NSString *note = (NSString*)ABRecordCopyValue(person, kABPersonNoteProperty);

     if(note != nil)

       label.text = [label.text stringByAppendingFormat:@"%@",note];

     //第一次添加該條記錄的時(shí)間

     NSString *firstknow = (NSString*)ABRecordCopyValue(person, kABPersonCreationDateProperty);

     NSLog(@"第一次添加該條記錄的時(shí)間%@\n",firstknow);

     //最后一次修改該條記錄的時(shí)間

     NSString *lastknow = (NSString*)ABRecordCopyValue(person, kABPersonModificationDateProperty);

     NSLog(@"最后一次修改該條記錄的時(shí)間%@\n",lastknow);

     //獲取email多值

     ABMultiValueRef email = ABRecordCopyValue(person, kABPersonEmailProperty);

     int emailcount = ABMultiValueGetCount(email);

     for (int x = 0; x < emailcount; x++)

    {

       //獲取email Label

       NSString* emailLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(email, x));

       //獲取email值

       NSString* emailContent = (NSString*)ABMultiValueCopyValueAtIndex(email, x);

       label.text = [label.text stringByAppendingFormat:@"%@:%@",emailLabel,emailContent];

    }

     //讀取地址多值

     ABMultiValueRef address = ABRecordCopyValue(person, kABPersonAddressProperty);

     int count = ABMultiValueGetCount(address);

     for(int j = 0; j < count; j++)

    {

       //獲取地址Label

       NSString* addressLabel = (NSString*)ABMultiValueCopyLabelAtIndex(address, j);

       label.text = [label.text stringByAppendingFormat:@"%@",addressLabel];

       //獲取該label下的地址6屬性

       NSDictionary* personaddress =(NSDictionary*) ABMultiValueCopyValueAtIndex(address, j);

       NSString* country = [personaddress valueForKey:(NSString *)kABPersonAddressCountryKey];

       if(country != nil)

         label.text = [label.text stringByAppendingFormat:@"國家:%@",country];

       NSString* city = [personaddress valueForKey:(NSString *)kABPersonAddressCityKey];

       if(city != nil)

         label.text = [label.text stringByAppendingFormat:@"城市:%@",city];

       NSString* state = [personaddress valueForKey:(NSString *)kABPersonAddressStateKey];

       if(state != nil)

         label.text = [label.text stringByAppendingFormat:@"?。?@",state];

       NSString* street = [personaddress valueForKey:(NSString *)kABPersonAddressStreetKey];

       if(street != nil)

         label.text = [label.text stringByAppendingFormat:@"街道:%@",street];

       NSString* zip = [personaddress valueForKey:(NSString *)kABPersonAddressZIPKey];

       if(zip != nil)

         label.text = [label.text stringByAppendingFormat:@"郵編:%@",zip];

       NSString* coutntrycode = [personaddress valueForKey:(NSString*)kABPersonAddressCountryCodeKey];

       if(coutntrycode != nil)

         label.text = [label.text stringByAppendingFormat:@"國家編號(hào):%@",coutntrycode];

    }

     //獲取dates多值

     ABMultiValueRef dates = ABRecordCopyValue(person, kABPersonDateProperty);

     int datescount = ABMultiValueGetCount(dates);

     for (int y = 0; y < datescount; y++)

    {

       //獲取dates Label

       NSString* datesLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(dates, y));

       //獲取dates值

       NSString* datesContent = (NSString*)ABMultiValueCopyValueAtIndex(dates, y);

       label.text = [label.text stringByAppendingFormat:@"%@:%@",datesLabel,datesContent];

    }

     //獲取kind值

     CFNumberRef recordType = ABRecordCopyValue(person, kABPersonKindProperty);

     if (recordType == kABPersonKindOrganization) {

       // it's a company

       NSLog(@"it's a company");

    } else {

       // it's a person, resource, or room

       NSLog(@"it's a person, resource, or room");

    }

     //獲取IM多值

     ABMultiValueRef instantMessage = ABRecordCopyValue(person, kABPersonInstantMessageProperty);

     for (int l = 1; l < ABMultiValueGetCount(instantMessage); l++)

    {

       //獲取IM Label

       NSString* instantMessageLabel = (NSString*)ABMultiValueCopyLabelAtIndex(instantMessage, l);

       label.text = [label.text stringByAppendingFormat:@"%@",instantMessageLabel];

       //獲取該label下的2屬性

       NSDictionary* instantMessageContent =(NSDictionary*)ABMultiValueCopyValueAtIndex(instantMessage, l);

       NSString* username = [instantMessageContent valueForKey:(NSString*)kABPersonInstantMessageUsernameKey];

       if(username != nil)

         label.text = [label.text stringByAppendingFormat:@"username:%@",username];

       NSString* service = [instantMessageContent valueForKey:(NSString*)kABPersonInstantMessageServiceKey];

       if(service != nil)

         label.text = [label.text stringByAppendingFormat:@"service:%@",service];

    }

     //讀取電話多值

     ABMultiValueRef phone = ABRecordCopyValue(person, kABPersonPhoneProperty);

     for (int k = 0; k<ABMultiValueGetCount(phone); k++)

    {

       //獲取電話Label

       NSString * personPhoneLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(phone, k));

       //獲取該Label下的電話值

       NSString * personPhone = (NSString*)ABMultiValueCopyValueAtIndex(phone, k);

       label.text = [label.text stringByAppendingFormat:@"%@:%@",personPhoneLabel,personPhone];

    }

     //獲取URL多值

     ABMultiValueRef url = ABRecordCopyValue(person, kABPersonURLProperty);

     for (int m = 0; m < ABMultiValueGetCount(url); m++)

    {

       //獲取電話Label

       NSString * urlLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(url, m));

       //獲取該Label下的電話值

       NSString * urlContent = (NSString*)ABMultiValueCopyValueAtIndex(url,m);

       label.text = [label.text stringByAppendingFormat:@"%@:%@",urlLabel,urlContent];

    }

     //讀取照片

     NSData *p_w_picpath = (NSData*)ABPersonCopyImageData(person);

     UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(200, 0, 50, 50)];

    [myImage setImage:[UIImage p_w_picpathWithData:p_w_picpath]];

    myImage.opaque = YES;

    [label addSubview:myImage];

  }

  //CF類型變量不適用ARC,需要釋放

   CFRelease(results);

   CFRelease(addressBook);

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“ios如何實(shí)現(xiàn)通訊錄聯(lián)系人各屬性獲取”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來學(xué)習(xí)!

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

標(biāo)題名稱:ios如何實(shí)現(xiàn)通訊錄聯(lián)系人各屬性獲取-創(chuàng)新互聯(lián)
本文鏈接:http://muchs.cn/article22/dpiijc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)公司、用戶體驗(yàn)、虛擬主機(jī)企業(yè)網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化