标签:
1,通讯录访问介绍
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
import UIKit import AddressBookUI class ViewController : UIViewController , ABPeoplePickerNavigationControllerDelegate { override func viewDidLoad() { super .viewDidLoad() // Do any additional setup after loading the view, typically from a nib. //弹出通讯录联系人选择界面 var picker = ABPeoplePickerNavigationController () picker.peoplePickerDelegate = self self .presentViewController(picker, animated: true ) { () -> Void in } } func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController !, didSelectPerson person: ABRecord !) { //获取姓 var lastName = ABRecordCopyValue (person, kABPersonLastNameProperty).takeRetainedValue() as ! String println ( "选中人的姓:\(lastName)" ) //获取名 var firstName = ABRecordCopyValue (person, kABPersonFirstNameProperty).takeRetainedValue() as ! String println ( "选中人的名:\(firstName)" ) //获取电话 var phoneValues: ABMutableMultiValueRef ? = ABRecordCopyValue (person, kABPersonPhoneProperty).takeRetainedValue() if phoneValues != nil { println ( "选中人电话:" ) for i in 0 ..< ABMultiValueGetCount (phoneValues){ // 获得标签名 var phoneLabel = ABMultiValueCopyLabelAtIndex (phoneValues, i).takeRetainedValue() as CFStringRef ; // 转为本地标签名(能看得懂的标签名,比如work、home) var localizedPhoneLabel = ABAddressBookCopyLocalizedLabel (phoneLabel) .takeRetainedValue() as ! String var value = ABMultiValueCopyValueAtIndex (phoneValues, i) var phone = value.takeRetainedValue() as ! String println ( "\(localizedPhoneLabel):\(phone)" ) } } } func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController !, didSelectPerson person: ABRecord !, property: ABPropertyID , identifier: ABMultiValueIdentifier ) { } //取消按钮点击 func peoplePickerNavigationControllerDidCancel(peoplePicker: ABPeoplePickerNavigationController !) { //去除地址选择界面 peoplePicker.dismissViewControllerAnimated( true , completion: { () -> Void in }) } func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController !, shouldContinueAfterSelectingPerson person: ABRecord !) -> Bool { return true } func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController !, shouldContinueAfterSelectingPerson person: ABRecord !, property: ABPropertyID , identifier: ABMultiValueIdentifier ) -> Bool { return true } } |
Swift - 访问通讯录联系人(使用系统提供的通讯录交互界面)
标签:
原文地址:http://www.cnblogs.com/Free-Thinker/p/4843592.html