您的位置:首页 > 移动开发 > IOS开发

iOS 调用系统自带的通讯录

2015-11-12 14:48 579 查看
//
// ViewController.m
// 跳转到设置界面
//
// Created by 上官林海 on 15/11/12.
// Copyright © 2015年 chinaByte_SGLH. All rights reserved.
//

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

@interface ViewController ()<ABPeoplePickerNavigationControllerDelegate,
ABPersonViewControllerDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
[super
viewDidLoad];
UIButton * button = [[UIButton
alloc]initWithFrame:CGRectMake(100,
100, 100,
50)];
button.backgroundColor = [UIColor
redColor];
[button addTarget:self
action:@selector(button2)
forControlEvents:UIControlEventTouchUpInside];
[self.view
addSubview:button];

}
- (void)button2{
ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController
alloc] init];
peoplePicker.peoplePickerDelegate =
self;
[self
presentViewController:peoplePicker
animated:YES
completion:nil];
}
- (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;
NSLog(@"%@",(__bridge
NSString*)value);
}];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: