iPhone取得用戶的電話本代碼
來源:易賢網(wǎng) 閱讀:891 次 日期:2015-01-22 10:02:38
溫馨提示:易賢網(wǎng)小編為您整理了“iPhone取得用戶的電話本代碼”,方便廣大網(wǎng)友查閱!

//取得用戶的電話本 代碼

-(void)getUserAddressBook{

//reDic = {"7":"數(shù)碼先鋒","1":"最愛街拍"} //打開電話本數(shù)據(jù)庫(kù)

ABAddressBookRef addressRef=ABAddressBookCreate();

//返回所有聯(lián)系人到一個(gè)數(shù)組中

CFArrayRef personArray = ABAddressBookCopyArrayOfAllPeople(addressRef);

NSMutableDictionary *jsonDictionary = [[NSMutableDictionary alloc]init];

//循環(huán)讀取每個(gè)聯(lián)系人

for (int i =0;i< p>

//得到當(dāng)前聯(lián)系人

ABRecordRef personRef=CFArrayGetValueAtIndex(personArray, i); //==============================================================================

CFStringRef firstname=ABRecordCopyValue(personRef, kABPersonFirstNameProperty);

CFStringRef lastname=ABRecordCopyValue(personRef, kABPersonLastNameProperty);

//CFStringRef userPhone = ABRecordCopyValue(personRef,kABPersonPhoneProperty );

NSString *allName;if([firstname isEqualToString:@""]||firstname==nil){if([lastname isEqualToString:@""]||lastname==nil){

allName=@"空";

}

}else if([lastname isEqualToString:@""]||lastname==nil){allName=[NSString stringWithFormat:@"];

}else if([firstname isEqualToString:@""]||firstname==nil){allName=[NSString stringWithFormat:@">];

}else{

allName=[NSString stringWithFormat:@"];

} // NSLog(@"); //============================================================================== // NSLog(@"); //用于循環(huán)計(jì)數(shù) int j; //用于保存有多項(xiàng)的屬性值 ABMultiValueRef values ; //==============================================================================

//循環(huán)讀出該項(xiàng)的所有值,如果需要修改讀出其它具有多項(xiàng)值的屬性,只需修改KAB...Property //具有多項(xiàng)值的屬性有電話,地址,email

values = (ABMultiValueRef) ABRecordCopyValue(personRef , kABPersonPhoneProperty);

//NSLog(@");

NSString *getPhoneNum;

for(j = 0 ;j < ABMultiValueGetCount(values); j++) {

getPhoneNum = [NSString stringWithFormat:@"%@", (NSString *)ABMultiValueCopyValueAtIndex(values, j)]; }if(ABMultiValueGetCount(values)==0){

getPhoneNum=@"空";

}//NSLog(@"); // values = (ABMultiValueRef) ABRecordCopyValue(personRef , kABPersonEmailProperty);// for( j = 0 ;j < ABMultiValueGetCount(values); j++)// { // NSLog(@"1-%@", (NSString *)ABMultiValueCopyValueAtIndex(values, j));// // }// // values = (ABMultiValueRef) ABRecordCopyValue(personRef , kABPersonAddressProperty);// for( j = 0 ;j < ABMultiValueGetCount(values); j++)// { // NSLog(@"2-%@", (NSString *)ABMultiValueCopyValueAtIndex(values, j));// // }[jsonDictionary setObject:getPhoneNum forKey:allName] ; //============================================================================== }

//NSLog(@"); NSString *str = [jsonDictionary JSONRepresentation];NSLog(@"); // NSString *d = [str JSONValue];[jsonDictionary release];

// NSString *str = [jsonDictionary JSONRepresentation];// NSMutableDictionary *d = [jsonDictionary JSONValue];// NSLog(@"%@" , [d description]); // [dlist release];//NSLog(@");}

更多信息請(qǐng)查看IT技術(shù)專欄

更多信息請(qǐng)查看技術(shù)文章
易賢網(wǎng)手機(jī)網(wǎng)站地址:iPhone取得用戶的電話本代碼
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 加入群交流 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65317125(9:00—18:00) 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)