首页 > 移动平台 > 详细

iOS开发--调用系统通讯录界面

时间:2015-04-09 22:03:09      阅读:247      评论:0      收藏:0      [点我收藏+]

今天写代码遇到了要调用系统通讯录,看了一些博客发现写的都是获取通讯录的内容,而不是调用系统的界面.

分享一下自己写的代码

第一步:引入

#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>

第二步:添加点击事件 创建一个通讯录界面 并以present的方式跳转

#pragma mark -- IBAction
- (IBAction)buttonClicked:(id)sender {
    ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
    peoplePicker.peoplePickerDelegate = self;
    [self presentViewController:peoplePicker animated:YES completion:nil];
}
第三步:实现代理方法ABPeoplePickerNavigationControllerDelegate

#pragma mark -- ABPeoplePickerNavigationControllerDelegate
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
    
    ABMultiValueRef valuesRef = ABRecordCopyValue(person, kABPersonPhoneProperty);
    CFIndex index = ABMultiValueGetIndexForIdentifier(valuesRef,identifier);
    CFStringRef value = ABMultiValueCopyValueAtIndex(valuesRef,index);
    
    [self dismissViewControllerAnimated:YES completion:^{
        self.textField.text = (__bridge NSString*)value;
    }];
}
这里需要说明一下的是 这里提供的方法开始适用于iOS8


iOS开发--调用系统通讯录界面

原文:http://blog.csdn.net/broccoliii/article/details/44964105

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!