ContactsUI(修改联系人)

来源:互联网 发布:java web用什么框架 编辑:程序博客网 时间:2024/06/02 15:14
  1. CNContactPickerViewController
    1. Required Keys
    2. Initializing View Controllers
    3. Displaying Contact Properties
    4. Notifying Delegate
    5. Contact Store
    6. Customizing Contact Card
    7. Highlighting a Property
    8. 实战
    9. 源代码
    10. 效果图

1 CNContactPickerViewController

CNContactPickerViewController可以显示一个联系人的相关信息、创建联系人或修改联系人。

1.1 Required Keys

/// 获取联系人使用的描述符public class func descriptorForRequiredKeys() -> CNKeyDescriptor

1.2 Initializing View Controllers

/// 通过已有联系人初始化CNContactPickerViewControllerpublic convenience init(forContact contact: CNContact)/// 未知联系人初始化CNContactPickerViewControllerpublic convenience init(forUnknownContact contact: CNContact)/// 新建联系人初始化CNContactPickerViewControllerpublic convenience init(forNewContact contact: CNContact?)

1.3 Displaying Contact Properties

/// 联系人public var contact: CNContact { get }/// 所属分组public var parentGroup: CNGroup?/// 所属集合public var parentContainer: CNContainer?/// 联系人显示的名称public var alternateName: String?/// 相关信息public var message: String?/// 可显示的属性public var displayedPropertyKeys: [AnyObject]?

1.4 Notifying Delegate

/// 代理控制可显示属性,及获取修改后的联系人weak public var delegate: CNContactViewControllerDelegate?

1.5 Contact Store

/// 联系人存储库public var contactStore: CNContactStore?

1.6 Customizing Contact Card

/// 能否修改数据public var allowsEditing: Bool // YES by default/// 是否显示打电话、发短信等按钮public var allowsActions: Bool // YES by default/// 是否显示联系人的关联联系人public var shouldShowLinkedContacts: Bool // NO by default

1.7 Highlighting a Property

/// 属性高亮public func highlightPropertyWithKey(key: String, identifier: String?)

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 UIKitimport ContactsUI/// ContactsUI显示class YJContactsUIVC: UIViewController, CNContactViewControllerDelegate {    override func viewDidLoad() {        super.viewDidLoad()    }    override func didReceiveMemoryWarning() {        super.didReceiveMemoryWarning()        // Dispose of any resources that can be recreated.    }    // MARK: - Action        // MARK: CNContactViewController 测试    @IBAction func onClickCNContactViewController(sender: AnyObject) {        // 创建或修改联系人        let vc = CNContactViewController(forNewContact: nil)        vc.delegate = self        self.navigationController?.pushViewController(vc, animated: true)    }    // MARK: - CNContactViewControllerDelegate    func contactViewController(viewController: CNContactViewController, shouldPerformDefaultActionForContactProperty property: CNContactProperty) -> Bool {        print(__FUNCTION__)        print(property)        return true    }    func contactViewController(viewController: CNContactViewController, didCompleteWithContact contact: CNContact?) {        viewController.navigationController?.popViewControllerAnimated(true)        print(__FUNCTION__)        print(contact)    }}

2.2 效果图

 


Appendix

Sample Code

Swift

ContactsUI Framework Reference

Revision History

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

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

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

0 0