獲取通訊錄資料放到模型陣列裡
第一步在呼叫改方法之前,需要先新建乙個模型用來存放獲取到的聯絡人資料,大概如下
@property(nonatomic,strong)nsstring *firstname;
@property(nonatomic,strong)nsstring *lastname;
@property(nonatomic,strong)nsstring *middlename;
@property(nonatomic,strong)nsstring *prefix;
@property(nonatomic,strong)nsstring *suffix;
@property(nonatomic,strong)nsstring *nickname;
@property(nonatomic,strong)nsstring *firstnamephonetic;
@property(nonatomic,strong)nsstring *lastnamephonetic;
@property(nonatomic,strong)nsstring *middlenamephonetic;
@property(nonatomic,strong)nsstring *organization;
@property(nonatomic,strong)nsstring *jobtitle;
@property(nonatomic,strong)nsstring *department;
@property(nonatomic,strong)nsstring *birthday;
@property(nonatomic,strong)nsstring *note;
@property(nonatomic,strong)nsstring *firstknow;
@property(nonatomic,strong)nsstring *lastknow;
@property(nonatomic,strong)nsmutablearray *emailarr;
@property(nonatomic,strong)nsmutablearray *addressarr;
@property(nonatomic,strong)nsmutablearray *phonearr;
@property(nonatomic,strong)nsmutablearray *urlarr;
第二步直接呼叫該方法,下面**裡connectpeoplearr是個陣列,用來接收獲取到的存放著聯絡人資料的模型,mzconnectpeoplemodel即為上面內容的聯絡人模型
- (void)loadperson
);}else if (abaddressbookgetauthorizationstatus() == kabauthorizationstatusauthorized)
else );}}
- (void)copyaddressbook:(abaddressbookref)addressbook
//讀取位址多值
abmultivalueref address = abrecordcopyvalue(person, kabpersonaddressproperty);
int count = abmultivaluegetcount(address);
for(int j = 0; j < count; j++)
/*//獲取dates多值
abmultivalueref dates = abrecordcopyvalue(person, kabpersondateproperty);
int datescount = abmultivaluegetcount(dates);
for (int y = 0; y < datescount; y++)
//獲取kind值
cfnumberref recordtype = abrecordcopyvalue(person, kabpersonkindproperty);
if (recordtype == kabpersonkindorganization) else
//獲取im多值
abmultivalueref instantmessage = abrecordcopyvalue(person, kabpersoninstantmessageproperty);
for (int l = 1; l < abmultivaluegetcount(instantmessage); l++)
*///讀取**多值
abmultivalueref phone = abrecordcopyvalue(person, kabpersonphoneproperty);
for (int k = 0; k/*//獲取url多值
abmultivalueref url = abrecordcopyvalue(person, kabpersonurlproperty);
for (int m = 0; m < abmultivaluegetcount(url); m++)
//讀取**
nsdata *image = (nsdata*)abpersoncopyimagedata(person);
*/[_connectpeoplearr addobject:peoplemodel];
nslog(@"%@",peoplemodel.firstname);//名字
nslog(@"%@",peoplemodel.firstknow);
nslog(@"%@",peoplemodel.firstnamephonetic);
nslog(@"%@",peoplemodel.middlename);
nslog(@"%@",peoplemodel.prefix);
nslog(@"%@",peoplemodel.suffix);
nslog(@"%@",peoplemodel.note);
nslog(@"%@",peoplemodel.lastknow);
nslog(@"%@",peoplemodel.nickname);
nslog(@"%@",peoplemodel.organization);//公司
nslog(@"%@",peoplemodel.birthday);
nslog(@"%@",peoplemodel.department);
nslog(@"%@",peoplemodel.middlenamephonetic);
nslog(@"%@",peoplemodel.lastname);//姓氏
nslog(@"%@",peoplemodel.phonearr[1]);//"住宅:11123456666"
}
iOS 獲取手機通訊錄
首先匯入 addressbook.framework 獲取通訊錄資訊核心 如下 獲取通訊錄中每條資訊內容 abaddressbookref tmpaddressbook abaddressbookcreatewithoptions null,null dispatch semaphore t sem...
IOS 通訊錄獲取 五
參考 pragma mark 獲取訪問通訊錄授權 void address 授權訪問 else 傳送一次訊號 dispatch semaphore signal sema else pragma mark 聯絡人姓名 nsmutablearray readaddress 獲取所有聯絡人的陣列 cfa...
獲取ios通訊錄資訊
包含相應地庫之後直接呼叫 import import void readallpeoples dispatch semaphore wait sema,dispatch time forever else 取得通訊錄失敗 if tmpaddressbook nil 將通訊錄中的資訊用陣列方式讀出 n...