【发布时间】:2018-12-04 00:52:03
【问题描述】:
编辑或选择属性时不会调用CNContactviewController 的委托。
在编辑新联系人时,应该调用contactViewController(_ viewController: CNContactViewController, shouldPerformDefaultActionFor property: CNContactProperty) 函数,但实际上没有。
当用户编辑/选择联系人属性时,您如何获得通知?
重现步骤:
- 复制下面的视图控制器。
- 编辑/选择联系人 财产。
预期行为:
每次编辑/选择属性时都会打印“yo”。
实际行为:
什么都没有。
import Foundation
import Contacts
import ContactsUI
class ContactViewController: UIViewController, CNContactViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
createContact()
}
func createContact() {
let contactController = CNContactViewController(forNewContact: nil)
contactController.delegate = self
contactController.allowsEditing = true
contactController.allowsActions = true
contactController.displayedPropertyKeys = [CNContactPostalAddressesKey, CNContactPhoneNumbersKey, CNContactGivenNameKey]
contactController.view.layoutIfNeeded()
present(contactController, animated:true)
}
// =============================================================================================================
// MARK: CNContactViewControllerDelegate Functions
// =============================================================================================================
func contactViewController(_ viewController: CNContactViewController, didCompleteWith contact: CNContact?) {
viewController.dismiss(animated: true, completion: nil)
print("hi")
}
func contactViewController(_ viewController: CNContactViewController, shouldPerformDefaultActionFor property: CNContactProperty) -> Bool {
print("yo")
return true
}
// =============================================================================================================
// MARK: UIViewController Functions
// =============================================================================================================
override var prefersStatusBarHidden: Bool {
return true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
【问题讨论】:
标签: ios swift contacts cncontact