cameraManager.addPreviewLayerToView causes crash
henryhardy opened this issue · comments
When calling .addPreviewLayerToView I am getting a crash - (llbd) is the error thrown, with a trace of
* thread #2: tid = 0x258e52, 0x00000001857a0d74 libsystem_kernel.dylib`__abort_with_payload + 8, queue = 'com.apple.root.default-qos', stop reason = signal SIGABRT
* frame #0: 0x00000001857a0d74 libsystem_kernel.dylib`__abort_with_payload + 8
frame #1: 0x000000018579d480 libsystem_kernel.dylib`abort_with_payload_wrapper_internal + 100
frame #2: 0x000000018579d4c8 libsystem_kernel.dylib`abort_with_payload + 12
frame #3: 0x00000001889e0328 TCC`__CRASHING_DUE_TO_PRIVACY_VIOLATION__ + 260
frame #4: 0x00000001889e0224 TCC`__TCCAccessRequest_block_invoke.73 + 704
frame #5: 0x00000001889e3330 TCC`__tccd_send_block_invoke + 348
frame #6: 0x00000001858a601c libxpc.dylib`_xpc_connection_reply_callout + 80
frame #7: 0x00000001858a5f8c libxpc.dylib`_xpc_connection_call_reply + 40
frame #8: 0x000000010160121c libdispatch.dylib`_dispatch_client_callout + 16
frame #9: 0x000000010160f2d4 libdispatch.dylib`_dispatch_queue_override_invoke + 980
frame #10: 0x0000000101610e6c libdispatch.dylib`_dispatch_root_queue_drain + 584
frame #11: 0x0000000101610bb8 libdispatch.dylib`_dispatch_worker_thread3 + 140
frame #12: 0x00000001858662b8 libsystem_pthread.dylib`_pthread_wqthread + 1288
frame #13: 0x0000000185865da4 libsystem_pthread.dylib`start_wqthread + 4
It was working on earlier versions, but has since started doing this on Xcode - 8.1
If you don't want to follow the example app, try the quick fix I've written:
class ViewController: UIViewController {
let cameraManager = CameraManager()
@IBOutlet var singleCameraView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let cameraManager = CameraManager()
cameraManager.cameraDevice = .front
cameraManager.cameraOutputQuality = .high
cameraManager.flashMode = .off
cameraManager.showAccessPermissionPopupAutomatically = false
let currentCameraState = cameraManager.currentCameraStatus()
if currentCameraState == .notDetermined {
askForCameraPermissions()
}
// if currentCameraState == .ready {}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
cameraManager.resumeCaptureSession()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
cameraManager.stopCaptureSession()
}
func askForCameraPermissions() {
cameraManager.askUserForCameraPermission({ permissionGranted in
if permissionGranted {
self.addCameraToView()
}
})
}
fileprivate func addCameraToView()
{
cameraManager.addPreviewLayerToView(singleCameraView, newCameraOutputMode: CameraOutputMode.videoWithMic)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Hi! Sorry I actually solved this problem - it was super simple and just being being derp, but it wasn't explained in the readme - all it ended up being is that the app didn't have a Privacy - Camera Usage Description in the info.plist - the app just silently fails when it doesn't have this when you use libraries that make use of resources - so it wasn't with your library at all.
Yup, the same thing happened to me. Once I put the Privacy prompts in the Info.plist, the problem was solved. I just wanted to help anybody that might not want to use the UI provided in the demo app (I thought that was your problem lol)
Yeah I don't really like how Apple doesn't give any reason to the crash. Anywho i'll mark it as closed. I might put in a PR change to the readme just to make it easier for others going forward.