我一直在努力解决这个问题,但无法解决任何问题。 我有一个视图控制器,有效地站在主要故事板上。在该视图控制器内部,当发生将联系类型传递给操作的特定操作时。
该操作为传递的联系人打开一个新的联系人视图控制器,并允许用户根据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
}
任何建议都会非常感激,我一直在努力解决这个问题太久了。 谢谢!
解决: 得到它的工作。事实证明这是苹果框架中的一个错误。为了解决这个问题,我只是将它从Unknown Contact切换到New Contact,这显然没有这个bug。 部分新代码:
let newScreen = CNContactViewController(forNewContact: con)
newScreen.delegate = self
let navigationController = UINavigationController(rootViewController: newScreen)
self.present(navigationController, animated: true, completion: nil)
由于
答案 0 :(得分:1)
你能尝试使用这段代码
吗?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 unkvc = CNContactViewController(forUnknownContact: con)
unkvc.delegate = self
unkvc.allowsEditing = true
unkvc.allowsActions = true
unkvc.title = "Edit Contact"
self.navigationController?.isNavigationBarHidden = false
self.navigationController?.navigationItem.hidesBackButton = true
self.navigationController?.pushViewController(unkvc, animated: false)