我一直在研究这个问题,但无法解决任何问题。我有一个视图控制器,它有效地站在主故事板上。在该视图控制器内部,当发生将联系人类型传递给该操作的特定操作时。
该操作为传递的联系人打开一个新的联系人视图控制器,并允许用户根据 CNContactViewController 与联系人进行交互。一旦用户完成了联系人,它就会关闭,因为 didCompleteWith 方法,但是没有办法退出联系人控制器,而不实际创建联系人。
//change to new contact screen
let con = CNMutableContact()
con.givenName = familyComponents[0]
con.familyName = familyComponents[1]
let newEmail = CNLabeledValue(label: "Personal", value: objectComponents[2]
as NSString)
con.emailAddresses.append(newEmail)
con.phoneNumbers.append(CNLabeledValue(
label: "Home", value: CNPhoneNumber(stringValue: objectComponents[3])))
let newScreen = CNContactViewController(forUnknownContact: con)
newScreen.message = "Made using app"
newScreen.contactStore = CNContactStore()
newScreen.delegate = self
newScreen.allowsActions = true
let navigationController = UINavigationController(rootViewController:
newScreen)
self.present(navigationController, animated: true, completion: nil)
从navigationItems到navigationItems我都试过了,在我看来导航栏就在那里,因为可以用这行代码改变它的半透明性:
navigationController.navigationBar.isTranslucent = true
方法如下:
func contactViewController(_ viewController: CNContactViewController,
didCompleteWith contact: CNContact?) {
viewController.dismiss(animated: true, completion: nil)
inContact = false
}
func contactViewController(_ shouldPerformDefaultActionForviewController:
CNContactViewController, shouldPerformDefaultActionFor property:
CNContactProperty) -> Bool {
return false
}
任何建议将不胜感激,我一直在努力解决这个问题太久了。谢谢!
已解决:让它工作。原来这是苹果框架中的一个错误。为了解决这个问题,我只是将它从未知联系人切换到新联系人,显然没有这个错误。部分新代码:
let newScreen = CNContactViewController(forNewContact: con)
newScreen.delegate = self
let navigationController = UINavigationController(rootViewController: newScreen)
self.present(navigationController, animated: true, completion: nil)
谢谢