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;
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
add a comment |
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
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
add a comment |
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
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
ios swift iphone xcode
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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)
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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)
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
add a comment |
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)
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
add a comment |
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)
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)
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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