我当前正在启动一个新的测试项目,用于通过单独的(模式)视图导入客户端证书。该应用程序始终以“主视图”(Main View)视图开头,在该视图中,我有一些虚拟元素来测试连接是否有效。用户向我的应用添加文件后(例如,通过邮件打开文件或在模拟器中拖放文件),就会通过Segue显示“证书导入”视图。当用户点击“输入证书密码”文本字段时,键盘弹出。返回时,如果输入的密码对于导入的p12客户端证书正确,则调用.resignFirstResponder()并通过标签调用应用程序。我希望我的“证书导入”视图(Certificate Import View)在关闭应用程序或激活多任务处理时被关闭。我通过在CertificateImportViewController上的应用程序委托的applicationWillResignActive(application :)方法中调用dismiss(animated:completion :)来实现这一点。
现在,当在“证书导入视图”中显示键盘后,仅关闭我的应用程序或仅切换到多任务处理时,就会出现我的问题。
当我在以下状态下关闭/多任务应用程序时,我在调试器控制台中获得了相应的条目:
显示/显示键盘并且我在证书导入视图中:
[Snapshotting] Snapshotting a view (0x7fa91506b200, UIKeyboardImpl) that is not in a visible window requires afterScreenUpdates:YES.
即使我离开了证书导入视图并回到“主视图”:[Snapshotting] Snapshotting a view (0x7fa91506b200, UIKeyboardImpl) that is not in a visible window requires afterScreenUpdates:YES.
在“证书导入视图”中显示键盘后,离开应用程序,再次打开应用程序,然后关闭/多任务应用程序:[Snapshotting] Snapshotting a view (0x7f99e3821600, UIKeyboardImpl) that has not been rendered at least once requires afterScreenUpdates:YES.
我试图找出是什么原因使OS认为即使主视图从不显示键盘,它也必须拍摄包括键盘在内的快照。我还试图找出为什么键盘认为在关闭键盘后必须对键盘进行快照的方法(resignFirstResponder())。我不确定如何调试将证书导入视图保留在堆栈中的内容(我相信这可能是原因)。
AppDelegate.swift
func applicationWillResignActive(_ application: UIApplication) {
guard let rv = window?.rootViewController as? UINavigationController else {
print("No Navigation Controller")
return
}
if let r = rv.presentedViewController as? UINavigationController, let c = r.topViewController as? CertificateImportViewController {
c.dismiss(animated: true, completion: nil)
}
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
self.fileBlobURL = url
guard let rv = window?.rootViewController as? UINavigationController else {
print("No Navigation Controller")
return false
}
guard let myEntryViewController = rv.topViewController, myEntryViewController.title == "MainView" else {
print("Wrong View Controller")
return false
}
myEntryViewController.performSegue(withIdentifier: "ShowCertificateImport", sender: myEntryViewController)
return true
}
CertificateImportViewController.swift
class CertificateImportViewController: UIViewController {
var fileURL: URL?
var credential: URLCredential?
@IBOutlet weak var certpwTextField: UITextField!
@IBOutlet weak var certResult: UILabel!
@IBOutlet weak var saveButton: UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
certpwTextField.delegate = self
let appdelegate = UIApplication.shared.delegate as! AppDelegate
guard let u = appdelegate.fileBlobURL else {
print("No file blob path found!")
return
}
self.fileURL = u
}
@IBAction func cancel(_ sender: UIBarButtonItem) {
dismiss(animated: true, completion: nil)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
certpwTextField.resignFirstResponder()
certpwTextField.delegate = nil
}
}
答案 0 :(得分:0)
经过更多的研究,包括大量的反复试验,我意识到:
但是,如果将来有人找到解决此问题的解决方案,出于好奇,我将对它的完成方式非常感兴趣。