iOS开发-通讯录有界面

//

//  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

转载于:https://www.cnblogs.com/LiLihongqiang/p/7111082.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值