Xcode App Randomly closing when scanning QR CODEIgnore Xcode warnings when using CocoapodsiOS app with framework crashed on device, dyld: Library not loaded, Xcode 6 Beta“Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.” when using GCCXcode “Device Locked” When iPhone is unlockedHow to hide and show label when navigation VC1 to VC2 back and forthSwift 2 iOS 9 animation disappears after button text changedUpdate or reload UITableView after completion of delete action on detail viewHow to make root navigation bar transparent, but child navigation bars not?Swift vertical UICollectionView inside UITableViewStrange animation occurs when extending UIView

USPS Back Room - Trespassing?

Find the three digit Prime number P from the given unusual relationships

How to cut a climbing rope?

Is it truly impossible to tell what a CPU is doing?

In the 3D Zeldas, is it faster to roll or to simply walk?

Pirate democracy at its finest

Does pair production happen even when the photon is around a neutron?

Using credit/debit card details vs swiping a card in a payment (credit card) terminal

Is "cool" appropriate or offensive to use in IMs?

Is it legal to meet with potential future employers in the UK, whilst visiting from the USA

Why does the hash of infinity have the digits of π?

Can a British citizen living in France vote in both France and Britain in the European Elections?

Apt - strange requests to d16r8ew072anqo.cloudfront.net:80

What is a fully qualified name?

My players want to grind XP but we're using milestone advancement

Should one buy new hardware after a system compromise?

Can I tell a prospective employee that everyone in the team is leaving?

A steel cutting sword?

What could a self-sustaining lunar colony slowly lose that would ultimately prove fatal?

Which European Languages are not Indo-European?

Why did the person in charge of a principality not just declare themself king?

Can I connect my older mathematica front-end to the free wolfram engine?

Convert Byte array into collection of items of different types

When the Torah was almost lost and one (or several) Rabbis saved it?



Xcode App Randomly closing when scanning QR CODE


Ignore Xcode warnings when using CocoapodsiOS app with framework crashed on device, dyld: Library not loaded, Xcode 6 Beta“Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.” when using GCCXcode “Device Locked” When iPhone is unlockedHow to hide and show label when navigation VC1 to VC2 back and forthSwift 2 iOS 9 animation disappears after button text changedUpdate or reload UITableView after completion of delete action on detail viewHow to make root navigation bar transparent, but child navigation bars not?Swift vertical UICollectionView inside UITableViewStrange animation occurs when extending UIView






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-1















I am making a QR code scanner app where my camera finds the code and have to segue into another view. But i can segue into another view because the app randomly closes if i call the self.performSegue after i find the code.



If i do not call the segue the code prints but the camera is froze. The app does not close if i get rid of the segue line



import UIKit
import Firebase
import AVFoundation

class ScannerViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate

var intendedDest = String()
var codex = String()

var captureSession: AVCaptureSession!
var previewLayer: AVCaptureVideoPreviewLayer!

override func viewDidLoad()
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

view.backgroundColor = UIColor.black
captureSession = AVCaptureSession()

guard let videoCaptureDevice = AVCaptureDevice.default(for: .video) else return
let videoInput: AVCaptureDeviceInput

do
videoInput = try AVCaptureDeviceInput(device: videoCaptureDevice)
catch
return


if (captureSession.canAddInput(videoInput))
captureSession.addInput(videoInput)
else
failed()
return


let metadataOutput = AVCaptureMetadataOutput()

if (captureSession.canAddOutput(metadataOutput))
captureSession.addOutput(metadataOutput)

metadataOutput.setMetadataObjectsDelegate(self, queue: DispatchQueue.global(qos: .userInteractive))
metadataOutput.metadataObjectTypes = [.ean8, .ean13, .pdf417, .qr]
else
failed()
return


previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer.frame = view.layer.bounds
previewLayer.videoGravity = .resizeAspectFill
view.layer.addSublayer(previewLayer)

captureSession.startRunning()


func failed()
let ac = UIAlertController(title: "Scanning not supported", message: "Your device does not support scanning a code from an item. Please use a device with a camera.", preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "OK", style: .default))
present(ac, animated: true)
captureSession = nil


override func viewWillAppear(_ animated: Bool)
super.viewWillAppear(animated)

if (captureSession?.isRunning == false)
captureSession.startRunning()



override func viewWillDisappear(_ animated: Bool)
super.viewWillDisappear(animated)

if (captureSession?.isRunning == true)
captureSession.stopRunning()



override func didReceiveMemoryWarning()
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.


func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection)
captureSession.stopRunning()

if let metadataObject = metadataObjects.first
guard let readableObject = metadataObject as? AVMetadataMachineReadableCodeObject else return
guard let stringValue = readableObject.stringValue else return
AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
found(code: stringValue)


self.performSegue(withIdentifier: "toTimerView", sender: self)


func found(code: String)
// qr code found!
print(code)
codex = code
print(codex)


override func prepare(for segue: UIStoryboardSegue, sender: Any?)
if let destination = segue.destination as? TimerViewController
destination.intendedDestxx = intendedDest



override var prefersStatusBarHidden: Bool
return true


override var supportedInterfaceOrientations: UIInterfaceOrientationMask
return .portrait


'''









share|improve this question
























  • What message you see in console when app crash?

    – ManWithBear
    Mar 24 at 2:30











  • 2019-03-23 22:36:40.088283-0400 PassApp[16852:3416514] [Animation] +[UIView setAnimationsEnabled:] being called from a background thread. Performing any operation from a background thread on UIView or a subclass is not supported and may result in unexpected and insidious behavior.

    – Aryan Patel
    Mar 24 at 2:37











  • Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'accessing _cachedSystemAnimationFence requires the main thread' *** First throw call stack:

    – Aryan Patel
    Mar 24 at 2:38











  • What is an Xcode app?

    – dandan78
    Mar 24 at 8:14

















-1















I am making a QR code scanner app where my camera finds the code and have to segue into another view. But i can segue into another view because the app randomly closes if i call the self.performSegue after i find the code.



If i do not call the segue the code prints but the camera is froze. The app does not close if i get rid of the segue line



import UIKit
import Firebase
import AVFoundation

class ScannerViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate

var intendedDest = String()
var codex = String()

var captureSession: AVCaptureSession!
var previewLayer: AVCaptureVideoPreviewLayer!

override func viewDidLoad()
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

view.backgroundColor = UIColor.black
captureSession = AVCaptureSession()

guard let videoCaptureDevice = AVCaptureDevice.default(for: .video) else return
let videoInput: AVCaptureDeviceInput

do
videoInput = try AVCaptureDeviceInput(device: videoCaptureDevice)
catch
return


if (captureSession.canAddInput(videoInput))
captureSession.addInput(videoInput)
else
failed()
return


let metadataOutput = AVCaptureMetadataOutput()

if (captureSession.canAddOutput(metadataOutput))
captureSession.addOutput(metadataOutput)

metadataOutput.setMetadataObjectsDelegate(self, queue: DispatchQueue.global(qos: .userInteractive))
metadataOutput.metadataObjectTypes = [.ean8, .ean13, .pdf417, .qr]
else
failed()
return


previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer.frame = view.layer.bounds
previewLayer.videoGravity = .resizeAspectFill
view.layer.addSublayer(previewLayer)

captureSession.startRunning()


func failed()
let ac = UIAlertController(title: "Scanning not supported", message: "Your device does not support scanning a code from an item. Please use a device with a camera.", preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "OK", style: .default))
present(ac, animated: true)
captureSession = nil


override func viewWillAppear(_ animated: Bool)
super.viewWillAppear(animated)

if (captureSession?.isRunning == false)
captureSession.startRunning()



override func viewWillDisappear(_ animated: Bool)
super.viewWillDisappear(animated)

if (captureSession?.isRunning == true)
captureSession.stopRunning()



override func didReceiveMemoryWarning()
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.


func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection)
captureSession.stopRunning()

if let metadataObject = metadataObjects.first
guard let readableObject = metadataObject as? AVMetadataMachineReadableCodeObject else return
guard let stringValue = readableObject.stringValue else return
AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
found(code: stringValue)


self.performSegue(withIdentifier: "toTimerView", sender: self)


func found(code: String)
// qr code found!
print(code)
codex = code
print(codex)


override func prepare(for segue: UIStoryboardSegue, sender: Any?)
if let destination = segue.destination as? TimerViewController
destination.intendedDestxx = intendedDest



override var prefersStatusBarHidden: Bool
return true


override var supportedInterfaceOrientations: UIInterfaceOrientationMask
return .portrait


'''









share|improve this question
























  • What message you see in console when app crash?

    – ManWithBear
    Mar 24 at 2:30











  • 2019-03-23 22:36:40.088283-0400 PassApp[16852:3416514] [Animation] +[UIView setAnimationsEnabled:] being called from a background thread. Performing any operation from a background thread on UIView or a subclass is not supported and may result in unexpected and insidious behavior.

    – Aryan Patel
    Mar 24 at 2:37











  • Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'accessing _cachedSystemAnimationFence requires the main thread' *** First throw call stack:

    – Aryan Patel
    Mar 24 at 2:38











  • What is an Xcode app?

    – dandan78
    Mar 24 at 8:14













-1












-1








-1








I am making a QR code scanner app where my camera finds the code and have to segue into another view. But i can segue into another view because the app randomly closes if i call the self.performSegue after i find the code.



If i do not call the segue the code prints but the camera is froze. The app does not close if i get rid of the segue line



import UIKit
import Firebase
import AVFoundation

class ScannerViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate

var intendedDest = String()
var codex = String()

var captureSession: AVCaptureSession!
var previewLayer: AVCaptureVideoPreviewLayer!

override func viewDidLoad()
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

view.backgroundColor = UIColor.black
captureSession = AVCaptureSession()

guard let videoCaptureDevice = AVCaptureDevice.default(for: .video) else return
let videoInput: AVCaptureDeviceInput

do
videoInput = try AVCaptureDeviceInput(device: videoCaptureDevice)
catch
return


if (captureSession.canAddInput(videoInput))
captureSession.addInput(videoInput)
else
failed()
return


let metadataOutput = AVCaptureMetadataOutput()

if (captureSession.canAddOutput(metadataOutput))
captureSession.addOutput(metadataOutput)

metadataOutput.setMetadataObjectsDelegate(self, queue: DispatchQueue.global(qos: .userInteractive))
metadataOutput.metadataObjectTypes = [.ean8, .ean13, .pdf417, .qr]
else
failed()
return


previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer.frame = view.layer.bounds
previewLayer.videoGravity = .resizeAspectFill
view.layer.addSublayer(previewLayer)

captureSession.startRunning()


func failed()
let ac = UIAlertController(title: "Scanning not supported", message: "Your device does not support scanning a code from an item. Please use a device with a camera.", preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "OK", style: .default))
present(ac, animated: true)
captureSession = nil


override func viewWillAppear(_ animated: Bool)
super.viewWillAppear(animated)

if (captureSession?.isRunning == false)
captureSession.startRunning()



override func viewWillDisappear(_ animated: Bool)
super.viewWillDisappear(animated)

if (captureSession?.isRunning == true)
captureSession.stopRunning()



override func didReceiveMemoryWarning()
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.


func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection)
captureSession.stopRunning()

if let metadataObject = metadataObjects.first
guard let readableObject = metadataObject as? AVMetadataMachineReadableCodeObject else return
guard let stringValue = readableObject.stringValue else return
AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
found(code: stringValue)


self.performSegue(withIdentifier: "toTimerView", sender: self)


func found(code: String)
// qr code found!
print(code)
codex = code
print(codex)


override func prepare(for segue: UIStoryboardSegue, sender: Any?)
if let destination = segue.destination as? TimerViewController
destination.intendedDestxx = intendedDest



override var prefersStatusBarHidden: Bool
return true


override var supportedInterfaceOrientations: UIInterfaceOrientationMask
return .portrait


'''









share|improve this question
















I am making a QR code scanner app where my camera finds the code and have to segue into another view. But i can segue into another view because the app randomly closes if i call the self.performSegue after i find the code.



If i do not call the segue the code prints but the camera is froze. The app does not close if i get rid of the segue line



import UIKit
import Firebase
import AVFoundation

class ScannerViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate

var intendedDest = String()
var codex = String()

var captureSession: AVCaptureSession!
var previewLayer: AVCaptureVideoPreviewLayer!

override func viewDidLoad()
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

view.backgroundColor = UIColor.black
captureSession = AVCaptureSession()

guard let videoCaptureDevice = AVCaptureDevice.default(for: .video) else return
let videoInput: AVCaptureDeviceInput

do
videoInput = try AVCaptureDeviceInput(device: videoCaptureDevice)
catch
return


if (captureSession.canAddInput(videoInput))
captureSession.addInput(videoInput)
else
failed()
return


let metadataOutput = AVCaptureMetadataOutput()

if (captureSession.canAddOutput(metadataOutput))
captureSession.addOutput(metadataOutput)

metadataOutput.setMetadataObjectsDelegate(self, queue: DispatchQueue.global(qos: .userInteractive))
metadataOutput.metadataObjectTypes = [.ean8, .ean13, .pdf417, .qr]
else
failed()
return


previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer.frame = view.layer.bounds
previewLayer.videoGravity = .resizeAspectFill
view.layer.addSublayer(previewLayer)

captureSession.startRunning()


func failed()
let ac = UIAlertController(title: "Scanning not supported", message: "Your device does not support scanning a code from an item. Please use a device with a camera.", preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "OK", style: .default))
present(ac, animated: true)
captureSession = nil


override func viewWillAppear(_ animated: Bool)
super.viewWillAppear(animated)

if (captureSession?.isRunning == false)
captureSession.startRunning()



override func viewWillDisappear(_ animated: Bool)
super.viewWillDisappear(animated)

if (captureSession?.isRunning == true)
captureSession.stopRunning()



override func didReceiveMemoryWarning()
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.


func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection)
captureSession.stopRunning()

if let metadataObject = metadataObjects.first
guard let readableObject = metadataObject as? AVMetadataMachineReadableCodeObject else return
guard let stringValue = readableObject.stringValue else return
AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
found(code: stringValue)


self.performSegue(withIdentifier: "toTimerView", sender: self)


func found(code: String)
// qr code found!
print(code)
codex = code
print(codex)


override func prepare(for segue: UIStoryboardSegue, sender: Any?)
if let destination = segue.destination as? TimerViewController
destination.intendedDestxx = intendedDest



override var prefersStatusBarHidden: Bool
return true


override var supportedInterfaceOrientations: UIInterfaceOrientationMask
return .portrait


'''






ios swift iphone xcode






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 8:09









ManWithBear

1,854720




1,854720










asked Mar 24 at 2:27









Aryan PatelAryan Patel

636




636












  • What message you see in console when app crash?

    – ManWithBear
    Mar 24 at 2:30











  • 2019-03-23 22:36:40.088283-0400 PassApp[16852:3416514] [Animation] +[UIView setAnimationsEnabled:] being called from a background thread. Performing any operation from a background thread on UIView or a subclass is not supported and may result in unexpected and insidious behavior.

    – Aryan Patel
    Mar 24 at 2:37











  • Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'accessing _cachedSystemAnimationFence requires the main thread' *** First throw call stack:

    – Aryan Patel
    Mar 24 at 2:38











  • What is an Xcode app?

    – dandan78
    Mar 24 at 8:14

















  • What message you see in console when app crash?

    – ManWithBear
    Mar 24 at 2:30











  • 2019-03-23 22:36:40.088283-0400 PassApp[16852:3416514] [Animation] +[UIView setAnimationsEnabled:] being called from a background thread. Performing any operation from a background thread on UIView or a subclass is not supported and may result in unexpected and insidious behavior.

    – Aryan Patel
    Mar 24 at 2:37











  • Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'accessing _cachedSystemAnimationFence requires the main thread' *** First throw call stack:

    – Aryan Patel
    Mar 24 at 2:38











  • What is an Xcode app?

    – dandan78
    Mar 24 at 8:14
















What message you see in console when app crash?

– ManWithBear
Mar 24 at 2:30





What message you see in console when app crash?

– ManWithBear
Mar 24 at 2:30













2019-03-23 22:36:40.088283-0400 PassApp[16852:3416514] [Animation] +[UIView setAnimationsEnabled:] being called from a background thread. Performing any operation from a background thread on UIView or a subclass is not supported and may result in unexpected and insidious behavior.

– Aryan Patel
Mar 24 at 2:37





2019-03-23 22:36:40.088283-0400 PassApp[16852:3416514] [Animation] +[UIView setAnimationsEnabled:] being called from a background thread. Performing any operation from a background thread on UIView or a subclass is not supported and may result in unexpected and insidious behavior.

– Aryan Patel
Mar 24 at 2:37













Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'accessing _cachedSystemAnimationFence requires the main thread' *** First throw call stack:

– Aryan Patel
Mar 24 at 2:38





Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'accessing _cachedSystemAnimationFence requires the main thread' *** First throw call stack:

– Aryan Patel
Mar 24 at 2:38













What is an Xcode app?

– dandan78
Mar 24 at 8:14





What is an Xcode app?

– dandan78
Mar 24 at 8:14












1 Answer
1






active

oldest

votes


















0














According to your warning and crash message you accessing UI in background thread.

Make sure that your UI code is called in main thread.



In case of background threads you can fix it by:



DispatchQueue.main.async 
/// your code here



In your code I see that you setting yourself as delegate of image stream on background queue. It mean your segue called on background as well. Fix it by:



func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection)
captureSession.stopRunning()

if let metadataObject = metadataObjects.first
guard let readableObject = metadataObject as? AVMetadataMachineReadableCodeObject else return
guard let stringValue = readableObject.stringValue else return
AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
found(code: stringValue)


DispatchQueue.main.async
self.performSegue(withIdentifier: "toTimerView", sender: self)







share|improve this answer























  • Can i also call functions in this function as well or should i call functions in view did load?

    – Aryan Patel
    Mar 24 at 3:20











  • @AryanPatel I afraid I not understand you. What functions? In what function?

    – ManWithBear
    Mar 24 at 3:27











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320230%2fxcode-app-randomly-closing-when-scanning-qr-code%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














According to your warning and crash message you accessing UI in background thread.

Make sure that your UI code is called in main thread.



In case of background threads you can fix it by:



DispatchQueue.main.async 
/// your code here



In your code I see that you setting yourself as delegate of image stream on background queue. It mean your segue called on background as well. Fix it by:



func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection)
captureSession.stopRunning()

if let metadataObject = metadataObjects.first
guard let readableObject = metadataObject as? AVMetadataMachineReadableCodeObject else return
guard let stringValue = readableObject.stringValue else return
AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
found(code: stringValue)


DispatchQueue.main.async
self.performSegue(withIdentifier: "toTimerView", sender: self)







share|improve this answer























  • Can i also call functions in this function as well or should i call functions in view did load?

    – Aryan Patel
    Mar 24 at 3:20











  • @AryanPatel I afraid I not understand you. What functions? In what function?

    – ManWithBear
    Mar 24 at 3:27















0














According to your warning and crash message you accessing UI in background thread.

Make sure that your UI code is called in main thread.



In case of background threads you can fix it by:



DispatchQueue.main.async 
/// your code here



In your code I see that you setting yourself as delegate of image stream on background queue. It mean your segue called on background as well. Fix it by:



func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection)
captureSession.stopRunning()

if let metadataObject = metadataObjects.first
guard let readableObject = metadataObject as? AVMetadataMachineReadableCodeObject else return
guard let stringValue = readableObject.stringValue else return
AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
found(code: stringValue)


DispatchQueue.main.async
self.performSegue(withIdentifier: "toTimerView", sender: self)







share|improve this answer























  • Can i also call functions in this function as well or should i call functions in view did load?

    – Aryan Patel
    Mar 24 at 3:20











  • @AryanPatel I afraid I not understand you. What functions? In what function?

    – ManWithBear
    Mar 24 at 3:27













0












0








0







According to your warning and crash message you accessing UI in background thread.

Make sure that your UI code is called in main thread.



In case of background threads you can fix it by:



DispatchQueue.main.async 
/// your code here



In your code I see that you setting yourself as delegate of image stream on background queue. It mean your segue called on background as well. Fix it by:



func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection)
captureSession.stopRunning()

if let metadataObject = metadataObjects.first
guard let readableObject = metadataObject as? AVMetadataMachineReadableCodeObject else return
guard let stringValue = readableObject.stringValue else return
AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
found(code: stringValue)


DispatchQueue.main.async
self.performSegue(withIdentifier: "toTimerView", sender: self)







share|improve this answer













According to your warning and crash message you accessing UI in background thread.

Make sure that your UI code is called in main thread.



In case of background threads you can fix it by:



DispatchQueue.main.async 
/// your code here



In your code I see that you setting yourself as delegate of image stream on background queue. It mean your segue called on background as well. Fix it by:



func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection)
captureSession.stopRunning()

if let metadataObject = metadataObjects.first
guard let readableObject = metadataObject as? AVMetadataMachineReadableCodeObject else return
guard let stringValue = readableObject.stringValue else return
AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
found(code: stringValue)


DispatchQueue.main.async
self.performSegue(withIdentifier: "toTimerView", sender: self)








share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 24 at 2:43









ManWithBearManWithBear

1,854720




1,854720












  • Can i also call functions in this function as well or should i call functions in view did load?

    – Aryan Patel
    Mar 24 at 3:20











  • @AryanPatel I afraid I not understand you. What functions? In what function?

    – ManWithBear
    Mar 24 at 3:27

















  • Can i also call functions in this function as well or should i call functions in view did load?

    – Aryan Patel
    Mar 24 at 3:20











  • @AryanPatel I afraid I not understand you. What functions? In what function?

    – ManWithBear
    Mar 24 at 3:27
















Can i also call functions in this function as well or should i call functions in view did load?

– Aryan Patel
Mar 24 at 3:20





Can i also call functions in this function as well or should i call functions in view did load?

– Aryan Patel
Mar 24 at 3:20













@AryanPatel I afraid I not understand you. What functions? In what function?

– ManWithBear
Mar 24 at 3:27





@AryanPatel I afraid I not understand you. What functions? In what function?

– ManWithBear
Mar 24 at 3:27



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320230%2fxcode-app-randomly-closing-when-scanning-qr-code%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?