Ios 使二维码阅读器在停止时重新启动
我有一个二维码阅读器,当找到二维码时,它会在模式中打开我的detailViewController。在my detailViewController上,您可以取消模式,例如,如果它不是您想要扫描的正确二维码。问题是,在我的代码中,QR码读取器设置为停止,当找到QR码并且您关闭modal时,它不会再次启动?我怎样才能使它重新启动 这里是QR code viewcontroller中的我的代码,这是在查找QR代码并在底部停止QR阅读器时对我的应用程序的其余部分起作用的部分:Ios 使二维码阅读器在停止时重新启动,ios,swift,uiviewcontroller,qr-code,Ios,Swift,Uiviewcontroller,Qr Code,我有一个二维码阅读器,当找到二维码时,它会在模式中打开我的detailViewController。在my detailViewController上,您可以取消模式,例如,如果它不是您想要扫描的正确二维码。问题是,在我的代码中,QR码读取器设置为停止,当找到QR码并且您关闭modal时,它不会再次启动?我怎样才能使它重新启动 这里是QR code viewcontroller中的我的代码,这是在查找QR代码并在底部停止QR阅读器时对我的应用程序的其余部分起作用的部分: if metadataO
if metadataObj.stringValue != nil {
// messageLabel.text = metadataObj.stringValue
messageLabel.backgroundColor = UIColor(red: 46/255.0, green: 204/255.0, blue: 113/255.0, alpha: 1.0)
messageLabel.text = "QR code found!"
passData = metadataObj.stringValue as String
dispatch_async(dispatch_get_main_queue()) { [unowned self] in
self.performSegueWithIdentifier("SendDataSegue", sender: self.passData)
}
self.captureSession!.stopRunning() // This is the part stopping it
}
这是因为您正在停止捕获会话
self.captureSession!.stopRunning() // This is the part stopping it
解除ViewController后,您必须检查您的self.captureSession
是否为零,如果为零,则必须创建一个新的捕获会话,如果不是零,则必须再次启动该会话。如下所示
self.captureSession!.startRunning()
因此,在
viewdiload
中初始化captureSession,并在视图中显示启动会话。在解除ViewController时,不会调用viewdiload。这是因为您正在停止captureSession
self.captureSession!.stopRunning() // This is the part stopping it
解除ViewController后,您必须检查您的self.captureSession
是否为零,如果为零,则必须创建一个新的捕获会话,如果不是零,则必须再次启动该会话。如下所示
self.captureSession!.startRunning()
因此,在viewdiload
中初始化captureSession,并在视图中显示启动会话。在解除ViewController时,不会调用viewdiload。是否应将包含该代码的if语句放在viewdiload的顶部?我已添加了此代码,在viewDidLoad和DidReceiveMemoryWarning之间:override func ViewwillDisplay(动画:Bool){if captureSession==nil{captureSession!.startRunning()}
,但没有任何运气。解除时仍不会再次启动。如果captureSession!=nil{captureSession!.startRunning()}我应该将包含该代码的if语句放在viewDidLoad的顶部吗?我已经在viewDidLoad和didReceiveMemoryWarning之间添加了此代码:覆盖函数viewwillDisplay(动画:Bool){if captureSession==nil{captureSession!.startRunning()}
但是运气不好。解除时仍不会再次启动。如果captureSession!=无{captureSession!.startRunning()}