我只想使用contactsUI CNContactViewController.init(forNewContact: a)作为视图,并将值传递给服务器。然而,现在func还添加了一个联系人到地址簿/联系人应用程序,它有可能防止这种情况吗?
发布于 2016-08-15 16:35:39
联系人框架参考:Framework/
样本: ViewController.swift
import UIKit
import ContactsUI
class ViewController: UIViewController, CNContactPickerDelegate {
let contactPickerViewController = CNContactPickerViewController()
@IBOutlet var titleLabel: UILabel!
@IBOutlet var valueLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
contactPickerViewController.delegate = self
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func touchUpInside(sender: UIButton) {
self.presentViewController(contactPickerViewController, animated: true, completion: nil)
}
func contactPicker(picker: CNContactPickerViewController, didSelectContactProperty contactProperty: CNContactProperty) {
titleLabel.text = ""
valueLabel.text = ""
if let label = contactProperty.label {
titleLabel.text = CNLabeledValue.localizedStringForLabel(label)
}
if let phone = contactProperty.value as? CNPhoneNumber {
valueLabel.text = phone.stringValue
}
if let stringData = contactProperty.value as? String {
valueLabel.text = stringData
}
if let adress = contactProperty.value as? CNPostalAddress {
let adressString = adress.street + " " + adress.city + " " + adress.country + " " + adress.postalCode
valueLabel.text = adressString
}
}
}下载项目文件:https://www.dropbox.com/s/yqdhqld0osp508b/Archive.zip?dl=0
https://stackoverflow.com/questions/38949454
复制相似问题