我的Xcode非常糟糕所以不要评判我。当用户扫描无效的qr代码时,我试图暂停captureSession,这将触发警报消息。用户关闭消息后,captureSession将恢复。非常感谢任何帮助。
if metadataObj.stringValue == "Booth1"
{
captureSession?.stopRunning()
self.performSegue(withIdentifier: "Vote1", sender: self)
}
else {
captureSession?.stopRunning()
createAlert(title: "Please enter a valid verfication code", message: "")
if UIAlertAction.isDismissed {
captureSession?.startRunning()
}
}
//Creating alert
func createAlert (title: String, message: String)
{
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.default, handler: { (action) in alert.dismiss(animated: true, completion: nil)
}))
self.present(alert, animated: true, completion: nil)
}
答案 0 :(得分:0)
如果您想在用户从UIAlertController
中选择一个选项时执行某些操作,请在操作的处理程序中执行此操作。
alert.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.default, handler: { action in
self.captureSession?.startRunning()
})
这应该做你需要的,如果你有更具体的问题,请更新你的问题。