Sie können CNContactPickerViewController verwenden.
import UIKit
import Contacts
import ContactsUI
protocol AddContactViewControllerDelegate {
@available(iOS 9.0, *)
func didFetchContacts(contacts: [CNContact])
}
class ViewController: UIViewController,CNContactPickerDelegate {
var delegate: AddContactViewControllerDelegate!
override func viewDidLoad() {
super.viewDidLoad()
if #available(iOS 9.0, *) {
let contactPickerViewController = CNContactPickerViewController()
contactPickerViewController.predicateForSelectionOfContact = NSPredicate(format: "[email protected] > 0", argumentArray: nil)
contactPickerViewController.delegate = self
presentViewController(contactPickerViewController, animated: true, completion: nil)
} else {
// Fallback on earlier versions
}
}
// MARK: CNContactPickerDelegate function
@available(iOS 9.0, *)
func contactPicker(picker: CNContactPickerViewController, didSelectContact contact: CNContact) {
print(contact.phoneNumbers)
if (contact.isKeyAvailable(CNContactPhoneNumbersKey)) {
for phoneNumber:CNLabeledValue in contact.phoneNumbers {
let a = phoneNumber.value as! CNPhoneNumber
print("\(a.stringValue)")
}
}
// delegate.didFetchContacts([contact])
navigationController?.popViewControllerAnimated(true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
können Sie mir den Code für Objective-C senden –
jemand mir bitte helfen .. –
http://stackoverflow.com/questions/32802087/cnui-error-selection-predicates-are-set-but- the-delegate-does-not-implement-cont –