Kinja
Kinja

Reputation: 459

Resume session after UIAlert is dismissed

my Xcode is pretty lousy so don't judge me. I'm trying to pause the captureSession when a user scans an invalid qr code which will trigger an alert message. After the user dismiss the message the captureSession will resume. Really appreciate any help given.

        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)

}

Upvotes: 0

Views: 74

Answers (1)

Scriptable
Scriptable

Reputation: 19750

If you want to do something when a user selects an option from an UIAlertController you do this in the handler for the action.

alert.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.default, handler: { action in 

      self.captureSession?.startRunning()
})

This should do what you need, if you are having a more specific issue please update your question.

Upvotes: 0

Related Questions