• 爱情文章
  • 亲情文章
  • 友情文章
  • 生活随笔
  • 校园文章
  • 经典文章
  • 人生哲理
  • 励志文章
  • 搞笑文章
  • 心情日记
  • 英语文章
  • 范文大全
  • 作文大全
  • 新闻阅读
  • 当前位置: 山茶花美文网 > 新闻阅读 > 正文

    微信电话本怎么用免费 [iPhone取得用户的电话本代码]

    时间:2020-05-29来源:山茶花美文网 本文已影响 山茶花美文网手机站

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

    -(void)getUserAddressBook{

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

    ABAddressBookRef addressRef=ABAddressBookCreate();

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

    CFArrayRef personArray = ABAddressBookCopyArrayOfAllPeople(addressRef);

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

    //循环读取每个联系人

    for (int i =0;i< p>

    //得到当前联系人

    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);}

    • 微信电话本怎么用免费 [iPhone取得用户的电话本代码] 相关文章:
    • 爱情文章
    • 亲情文章
    • 友情文章
    • 随笔
    • 哲理
    • 励志
    • 范文大全