取得用户的电话本

  //取得用户的电话本 代码

-(void)getUserAddressBook{

  //reDic = {"7":"数码先锋","1":"最爱街拍"} //打开电话本数据库   

   ABAddressBookRef addressRef=ABAddressBookCreate();     

   //返回所有联系人到一个数组中    

CFArrayRef personArray = ABAddressBookCopyArrayOfAllPeople(addressRef);   

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

 //循环读取每个联系人   

 for (int i =0;i<ABAddressBookGetPersonCount(addressRef);i++){     

           //得到当前联系人      

  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:@"%@",firstname];

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

}else{

allName=[NSString stringWithFormat:@"%@+%@",firstname,lastname];

}       // NSLog(@"%d===%@--%@.",i,(NSString*)firstname,(NSString*)lastname);//NSLog(@"allName=%@",allName);        //==============================================================================      //  NSLog(@"%d===%@",i,(NSString*)userPhone);                //用于循环计数        int j;        //用于保存有多项的属性值        ABMultiValueRef values ;                //==============================================================================      

  //循环读出该项的所有值,如果需要修改读出其它具有多项值的属性,只需修改KAB...Property        //具有多项值的属性有电话,地址,email     

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

//NSLog(@"values===%@",values);

NSString *getPhoneNum;  

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

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

getPhoneNum=@"空";

}//NSLog(@"getPhoneNum=====%@",getPhoneNum);       // 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(@"addressbook=%@",jsonDictionary);    NSString *str = [jsonDictionary JSONRepresentation];NSLog(@"str===%@",str);  //  NSString *d = [str JSONValue];[jsonDictionary release];
  //  NSString *str = [jsonDictionary JSONRepresentation];//    NSMutableDictionary *d = [jsonDictionary JSONValue];//    NSLog(@"%@" , [d description]);       // [dlist release];//NSLog(@"addressbook=%@",jsonDictionary);}

posted @ 2010-11-25 14:11 SsQq 阅读(116) 评论(0) 编辑
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值