iOS匯入手機通訊錄

2021-07-26 16:06:49 字數 3970 閱讀 4218

abaddressbookref

addressbooks =

nil;

if([[

uidevice

currentdevice

].systemversion

floatvalue

] >=

6.0)

); dispatch_semaphore_wait

(sema,

dispatch_time_forever);

} else

//獲取通訊錄中的所有人

cfarrayref

allpeople =

abaddressbookcopyarrayofallpeople

(addressbooks); //

通訊錄中人數

cfindex

npeople =

abaddressbookgetpersoncount

(addressbooks);

//迴圈,獲取每個人的個人資訊

for(nsinteger

i =

0; i < npeople; i++)

else }

addressbook.

name

= namestring;

addressbook.

recordid

= (int

)abrecordgetrecordid

(person);;

abpropertyid

multiproperties = ;

nsinteger

multipropertiestotal =

sizeof

(multiproperties) /

sizeof

(abpropertyid);

for(

nsinteger

j =

0; j < multipropertiestotal; j++) //

獲取**號碼和

email

for(nsinteger

k =

0; k < valuescount; k++)

case1:

}cfrelease

(value); }

cfrelease

(valuesref); }

nsmutabledictionary

*jsondict=[

nsmutabledictionary

dictionary];

if(namestring .

length

== 0

|| namestring ==

nil)

[jsondict

setobject

:namestring

forkey

:@"nickname"];

if(addressbook.

tel.

length

> 0)

//將個人資訊新增到陣列中,迴圈完成後

addressbooktemp

中包含所有聯絡人的資訊 [

_addressbooktemp

addobject

:jsondict];

if(abname)

cfrelease

(abname); if

(ablastname)

cfrelease

(ablastname); if

(abfullname)

cfrelease

(abfullname); }

nsmutabledictionary

*dict = [

nsmutabledictionary

dictionary];

if(gettoken)

nsdata

*datafriends = [

nsjsonserialization

datawithjsonobject

:self

.addressbooktemp

options

:nsjsonwritingprettyprinted

error

:nil];

nsstring

*jsonstring = [[

nsstring

alloc

] initwithdata

:datafriends

encoding

:nsutf8stringencoding];

jsonstring=[jsonstring

stringbyreplacingoccurrencesofstring

:@"\r"

withstring

:@""];

jsonstring = [jsonstring

stringbytrimmingcharactersinset

:[nscharacterset

whitespaceandnewlinecharacterset

]];

nsstring

*newstr=[

importcontactlistviewcontroller

delspaceandnewline

:jsonstring];

nsmutablestring

*mustr=[

nsmutablestring

stringwithformat

:@"%@"

,newstr];

nsstring

*character =

nil;

for(inti=0

; ilength

; i++) }

nsstring

*character1 =

nil;

for(inti=0

; ilength

; i++) }

[dict

setobject

:mustr

forkey

:@"item"];

newnetwork

*request = [[

newnetwork

alloc

]init];

nsstring

*strurl=[

nsstring

stringwithformat

:@"api-user/import-phone-contacts"];

[request

postnewrequest

:dict

url:strurl];

[request

block

:^(id

responseobject) ); }

}];

} + (nsstring

*)delspaceandnewline:(

nsstring

*)string;;

[mutstr

replaceoccurrencesofstring

:@" "

withstring

:@""

options

:nsliteralsearch

range

:range];

nsrange

range2 = ;

[mutstr

replaceoccurrencesofstring

:@"\n"

withstring

:@""

options

:nsliteralsearch

range

:range2];

return

mutstr; }

ios手機通訊錄匯入應用

abaddressbookref addressbooks nil if uidevice currentdevice systemversion floatvalue 6.0 dispatch semaphore wait sema,dispatch time forever else 獲取通訊錄...

iOS 獲取手機通訊錄

首先匯入 addressbook.framework 獲取通訊錄資訊核心 如下 獲取通訊錄中每條資訊內容 abaddressbookref tmpaddressbook abaddressbookcreatewithoptions null,null dispatch semaphore t sem...

獲取手機通訊錄

在公司裡寫了一段上傳使用者通訊錄的 寫下來,以便以後查閱 獲取手機裡的通訊錄 獲取通訊錄 param context return 返回包含使用者名稱,與號碼的arraylist public arraylistgetcontact context context phones.close alla...