ContactsUI(选择联系人).md

1 CNContactPickerViewController

1.1 Displaying Contacts Properties

1.2 Notifying Delegate

1.3 Predicates For Selecting Contacts

2 实战演练

2.1 源代码

2.2 效果图


1 CNContactPickerViewController

CNContactPickerViewController支持快速选中联系人或联系人的属性,支持单选和多选。

1.1 Displaying Contacts Properties

/// 联系人名片可展示的信息
public var displayedPropertyKeys: [String]?

1.2 Notifying Delegate

/// 通过代理控制选择的联系人或联系人属性
weak public var delegate: CNContactPickerDelegate?

1.3 Predicates For Selecting Contacts

/// 晒选联系人
@NSCopying public var predicateForEnablingContact: NSPredicate? // e.g. emailAddresses.@count > 0

/// 可选得联系人
@NSCopying public var predicateForSelectionOfContact: NSPredicate? // e.g. emailAddresses.@count == 1

/// 可选的联系人属性
@NSCopying public var predicateForSelectionOfProperty: NSPredicate? // e.g. (key == 'emailAddresses') AND (value LIKE '*@apple.com')

2 实战演练

2.1 源代码

//
//  YJContactsUIVC.swift
//  Contact
//
//  CSDN:http://blog.csdn.net/y550918116j
//  GitHub:https://github.com/937447974/Blog
//
//  Created by yangjun on 16/1/14.
//  Copyright © 2016年 阳君. All rights reserved.
//

import UIKit
import ContactsUI

/// ContactsUI显示
class YJContactsUIVC: UIViewController, CNContactPickerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Action
    // MARK: CNContactPickerViewController 测试
    @IBAction func onClickCNContactPickerViewController(sender: AnyObject) {
        // 选择联系人或联系人的属性(如电话号码)
        let vc = CNContactPickerViewController()
        vc.delegate = self // 根据实现的代理方法指定单选、多选
        self.presentViewController(vc, animated: true, completion: nil)
    }

    // MARK: - CNContactPickerDelegate
    func contactPicker(picker: CNContactPickerViewController, didSelectContact contact: CNContact) {
        // 单选
        print(contact)
    }

}

2.2 效果图

 


Appendix

Sample Code

Swift

Contacts Framework Reference

CNContactPickerViewController Class Reference

Revision History

时间描述
2016-01-20博文完成

CSDN:http://blog.csdn.net/y550918116j

GitHub:https://github.com/937447974/Blog

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值