UIAlertController 在警报操作上移动到另一个控制器 - Swift



我正在尝试在警报视图操作上移动到另一个控制器。它按预期移动到下一个控制器,但一旦移动到另一个控制器,它就会再次显示相同的警报。请检查下面的代码。

func decode(decodedURL: String) {
let alertController = UIAlertController(title: "", message: "Confirm", preferredStyle: .alert)
let viewController = self.storyboard?.instantiateViewController(withIdentifier: "FormViewController") as? FormViewController
viewController?.fillData(dataDic: convertJsonStringToDictionary(jsonString: decodedURL))
let action1 = UIAlertAction(title: "Ok", style: .default) { (action) in       
self.navigationController?.show(viewController!, sender: true)
}

let action2 = UIAlertAction(title: "Cancel", style: .cancel) { (action:UIAlertAction) in
print("You've pressed cancel");       
}
alertController.addAction(action1)
alertController.addAction(action2)
self.present(alertController, animated: true, completion: nil)
}

调用下面的上述方法

func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
// Check if the metadataObjects array is not nil and it contains at least one object.
if metadataObjects.count == 0 {
qrCodeFrameView?.frame = CGRect.zero
messageLabel.text = "No code detected"
return
}
// Get the metadata object.
let metadataObj = metadataObjects[0] as! AVMetadataMachineReadableCodeObject
if supportedCodeTypes.contains(metadataObj.type) {
// If the found metadata is equal to the QR code metadata (or barcode) then update the status label's text and set the bounds
let barCodeObject = videoPreviewLayer?.transformedMetadataObject(for: metadataObj)
qrCodeFrameView?.frame = barCodeObject!.bounds
if metadataObj.stringValue != nil {
decode(decodedURL: metadataObj.stringValue!)
messageLabel.text = metadataObj.stringValue
}
}
}
func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection)

是委托函数

AVCaptureMetadataOutputObjectsDelegate

.它将继续被调用,直到您的捕获会话处于活动状态。

因此,当您导航到下一个屏幕时,只需停止捕获会话。

captureSession?.stopRunning() 
captureSession = nil

相关内容

  • 没有找到相关文章

最新更新