讀取通訊錄資訊

2022-09-02 12:06:07 字數 3433 閱讀 6559

-(void)readallpeoples

//取得本地通訊錄名柄

abaddressbookref tmpaddressbook = nil;

if([[uidevicecurrentdevice].systemversionfloatvalue]>=

6.0) {

tmpaddressbook=abaddressbookcreatewithoptions(

null

, null

);dispatch_semaphore_tsema=dispatch_semaphore_create(0);

abaddressbookrequestaccesswithcompletion(tmpaddressbook, ^(

bool

greanted, cferrorreferror){

dispatch_semaphore_signal(sema);

dispatch_semaphore_wait(sema,

dispatch_time_forever

);else

tmpaddressbook =abaddressbookcreate();

//取得本地所有聯絡人記錄

if (tmpaddressbook==nil) {

return ;

nsarray* tmppeoples = (

__bridgensarray*)abaddressbookcopyarrayofallpeople(tmpaddressbook);

for(id tmpperson in tmppeoples)

//獲取的聯絡人單一屬性:first name

nsstring* tmpfirstname = (

__bridgensstring*)abrecordcopyvalue((

__bridgeabrecordref)(tmpperson), kabpersonfirstnameproperty);

nslog(@"first name:%@", tmpfirstname);

//獲取的聯絡人單一屬性:last name

nsstring* tmplastname = (

__bridgensstring*)abrecordcopyvalue((

__bridgeabrecordref)(tmpperson), kabpersonlastnameproperty);

nslog(@"last name:%@", tmplastname);

//獲取的聯絡人單一屬性:nickname

nsstring* tmpnickname = (

__bridgensstring*)abrecordcopyvalue((

__bridgeabrecordref)(tmpperson), kabpersonnicknameproperty);

nslog(@"nickname:%@", tmpnickname);

//獲取的聯絡人單一屬性:company name

nsstring* tmpcompanyname = (

__bridgensstring*)abrecordcopyvalue((

__bridgeabrecordref)(tmpperson), kabpersonorganizationproperty);

nslog(@"company name:%@", tmpcompanyname);

//獲取的聯絡人單一屬性:job title

nsstring* tmpjobtitle= (

__bridgensstring*)abrecordcopyvalue((

__bridgeabrecordref)(tmpperson), kabpersonjobtitleproperty);

nslog(@"job title:%@", tmpjobtitle);

//獲取的聯絡人單一屬性:department name

nsstring* tmpdepartmentname = (

__bridgensstring*)abrecordcopyvalue((

__bridgeabrecordref)(tmpperson), kabpersondepartmentproperty);

nslog(@"department name:%@", tmpdepartmentname);

//獲取的聯絡人單一屬性:email(s)

abmultivaluereftmpemails = abrecordcopyvalue((

__bridgeabrecordref)(tmpperson), kabpersonemailproperty);

for(nsinteger j = 0; abmultivaluegetcount(tmpemails); j++)

nsstring* tmpemailindex = (__bridge

nsstring*)abmultivaluecopyvalueatindex(tmpemails, j);

nslog(@"emails%d:%@", j, tmpemailindex);

cfrelease(tmpemails);

//獲取的聯絡人單一屬性:birthday

nsdate* tmpbirthday = (

__bridgensdate*)abrecordcopyvalue((

__bridgeabrecordref)(tmpperson), kabpersonbirthdayproperty);

nslog(@"birthday:%@", tmpbirthday);

//獲取的聯絡人單一屬性:note

nsstring* tmpnote = (

__bridgensstring*)abrecordcopyvalue((

__bridgeabrecordref)(tmpperson), kabpersonnoteproperty);

nslog(@"note:%@", tmpnote);

//獲取的聯絡人單一屬性:generic phone number

abmultivaluereftmpphones = abrecordcopyvalue((

__bridgeabrecordref)(tmpperson), kabpersonphoneproperty);

for(nsinteger j = 0; j < abmultivaluegetcount(tmpphones); j++)

nsstring* tmpphoneindex = (__bridge

nsstring*)abmultivaluecopyvalueatindex(tmpphones, j);

nslog(@"tmpphoneindex%d:%@", j, tmpphoneindex);

cfrelease(tmpphones);

cfrelease(tmpaddressbook);

Swift 讀取通訊錄資訊

1,通訊錄訪問介紹 通訊錄是乙個資料庫,又叫位址簿 簿,裡面儲存了聯絡人的相關資訊。要實現訪問通訊錄有如下兩種方式 1 addressbook.framework框架 沒有介面,通過 來獲取所有聯絡人資訊 2 addressbookui.framework框架 通過系統提供的通訊錄互動介面來訪問 2...

ContentProvider讀取通訊錄和聯絡歷史

通過使用contentresolver讀取系統發布好的通訊錄相關的資料庫內容,並可以將裡面的資料取得,列表顯示。public class mainactivity extends activity null 隨意記錄乙個 一邊撥叫,這裡記錄迴圈中的最後乙個 string number c2.move...

Android讀取通訊錄資料

第一步,配置許可權 如果需要儲存,還需要儲存許可權 第二步,編寫聯絡人獲取工具類contractsutil public class contractsutil 根據uri查詢相應的contentprovider,cursor為獲取到的資料集 cursor cursor context.getcon...