博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS开发-通讯录有界面
阅读量:6938 次
发布时间:2019-06-27

本文共 2138 字,大约阅读时间需要 7 分钟。

//

//  ViewController.m

//  06-通讯录(有界面)

//

 

#import "ViewController.h"

#import <AddressBookUI/AddressBookUI.h>

@interface ViewController ()<ABPeoplePickerNavigationControllerDelegate>

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    

    

}

 

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    //创建联系人选择控制器在

    ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc]init];

    peoplePicker.peoplePickerDelegate = self;

    [self presentViewController:peoplePicker animated:YES completion:^{

        

    }];

    

}

 

//用户选择一个联系人可以挑用这个方法(如果实现了这个方法,就不会调用下面这个方法)

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person{

//    ABRecordRef

//    record -> 记录

    //底层有一个数据库,一个记录对应一个联系人的信息

    //name  id(学号)  age

    

//    NSLog(@"%d",person);

//    <#ABPropertyID property#>告诉我这条记录里面的什么内容

   CFStringRef firstStr =  ABRecordCopyValue(person,kABPersonFirstNameProperty);

    CFStringRef lastStr =  ABRecordCopyValue(person,kABPersonLastNameProperty);

    //桥接

    NSString *first = (__bridge NSString *)(firstStr);

    NSString *last = (__bridge NSString *)(lastStr);

    NSLog(@"first = %@  last = %@",first,last);

    CFRelease(firstStr);

    CFRelease(lastStr);

    //电话

    //AB框架里面的东西  等价于NSArray

    //住宅,公司 手机

    //CF框架下,内存自己管理,如果对象是  copy create等需要手动realse

  ABMultiValueRef  multiValueRef =  ABRecordCopyValue(person, kABPersonPhoneProperty);

   CFIndex index =  ABMultiValueGetCount(multiValueRef);

    for (int i = 0; i < index; i++) {

        //根据索引获取需要的电话

       CFStringRef phoneStr = ABMultiValueCopyLabelAtIndex(multiValueRef, i);

        NSString *phone = (__bridge NSString *)(phoneStr);

        NSLog(@"%@",phone);

        CFRelease(phoneStr);

        

    }

    CFRelease(multiValueRef);

    

    

}

 

//一个属性选择之后就会调用

//标识

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier NS_AVAILABLE_IOS(8_0){

    //property 属性 对应一个人的电话,地址,生日

    //如果有很多个的话,identifier来区分

    NSLog(@"%d",property);

    

}

 

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

 

@end

转载地址:http://hpfnl.baihongyu.com/

你可能感兴趣的文章
手机多图传输神器-快传正式版抢先评测
查看>>
分享三种简单的推广渠道,玩转引流精准粉
查看>>
U2L蔚然成风,曙光为什么能抢了VMware的风头?
查看>>
MySQL基础备忘(2)之视图
查看>>
MapGuide OpenSource 2.2 安装中的数字签名错误
查看>>
ubuntu分区
查看>>
艾伟_转载:学习 ASP.NET MVC (第五回)理论篇
查看>>
Amazon AWS云管理平台技术内幕,互联网营销
查看>>
【评论】GNU/Linux下有多少是GNU的?
查看>>
IE漏洞致数百万用户中招 快用瑞星卡卡打补丁
查看>>
瑞星义卖活动圆满结束 感谢用户积极参与
查看>>
【Oracle】SQL学习笔记1---基本概念及SELECT语句及提取和排序数据
查看>>
大流量网站的底层系统架构
查看>>
技巧:Vimdiff 使用(转)
查看>>
VirtualBox安装CentOS后如何安装增强功能
查看>>
3D数学知识简介
查看>>
AMD OpenCL大学课程(3)
查看>>
一种线程安全的单例模式实现
查看>>
memcached-1.4.4在ubuntu下编译的注意事项
查看>>
C# 常用命名空间
查看>>