zoukankan      html  css  js  c++  java
  • IOS 获取系统通讯录中的联系人信息

    - (IBAction)getAllContactFromSystem {
    ABAddressBookRef ab = ABAddressBookCreateWithOptions(NULL, NULL);
    ABAddressBookRequestAccessWithCompletion(ab, ^(bool granted, CFErrorRef error) {

    //取得通讯录访问授权
    ABAuthorizationStatus authorization= ABAddressBookGetAuthorizationStatus();
    if (authorization!=kABAuthorizationStatusAuthorized) {
    NSLog(@"尚未获得通讯录访问授权!");
    return ;
    }

    //取得通讯录中所有人员记录
    CFArrayRef allPeople= ABAddressBookCopyArrayOfAllPeople(ab);
    for (int i=0; i<CFArrayGetCount(allPeople); ++i) {
    ABRecordRef recordRef = CFArrayGetValueAtIndex(allPeople, i);
    //获取用户名
    NSString *firstName = (__bridge NSString *) ABRecordCopyValue(recordRef, kABPersonFirstNameProperty);
    NSString *lastName = (__bridge NSString *)ABRecordCopyValue(recordRef, kABPersonLastNameProperty);
    NSString *personName = [NSString stringWithFormat:@"%@%@",lastName,firstName];
    //获取手机号
    NSMutableArray *phoneNumbers = [NSMutableArray new];
    ABMultiValueRef phoneNumbersRef = ABRecordCopyValue(recordRef, kABPersonPhoneProperty);
    for(int j=0; j<ABMultiValueGetCount(phoneNumbersRef); ++j){
    NSString* phoneNumber = (__bridge NSString *)(ABMultiValueCopyValueAtIndex(phoneNumbersRef, j));
    phoneNumber = [phoneNumber stringByReplacingOccurrencesOfString:@"-" withString:@""];
    if (phoneNumber.length > 0) {
    [phoneNumbers addObject:phoneNumber];
    }
    }
    }

    //释放资源
    CFRelease(allPeople);
    });
    }

  • 相关阅读:
    Java实现 LeetCode 691 贴纸拼词(DFS+map记录)
    Java实现 LeetCode 691 贴纸拼词(DFS+map记录)
    PHP is_resource() 函数
    PHP is_float()、 is_double()、is_real()函数
    PHP is_object() 函数
    PHP is_numeric() 函数
    PHP is_null() 函数
    目标检测算法进展大盘点
    斯坦福大学李飞飞团队图像分类课程笔记
    激光雷达与应用
  • 原文地址:https://www.cnblogs.com/guoxiaoqian/p/5314734.html
Copyright © 2011-2022 走看看