Skip to content
This repository has been archived by the owner on Jun 13, 2019. It is now read-only.

Put start() in ViewDidLoad() causes crash #7

Closed
Jackson0111 opened this issue Jan 5, 2016 · 7 comments
Closed

Put start() in ViewDidLoad() causes crash #7

Jackson0111 opened this issue Jan 5, 2016 · 7 comments

Comments

@Jackson0111
Copy link

I have following code in ViewDidLoad() and it causes app crash with error 'Can't add a nil AVCaptureInput' :

override func viewDidLoad() {

    CameraEngine.startup()

    let preview: AVCaptureVideoPreviewLayer = CameraEngine.getPreviewLayer()

    preview.frame = self.view.bounds

    self.view.layer.addSublayer(preview)

    self.view.addSubview(takePhotoButton)

    cameraFlash.setImage(noFlash, forState: .Normal)

    CameraEngine.shareInstance().flash = false

    self.view.addSubview(cameraFlash) // flash light button

    photoLibrary.setImage(album, forState: .Normal)

    self.view.addSubview(photoLibrary) // open photo album button
}
@remirobert
Copy link
Owner

On simulator maybe ?

@Jackson0111
Copy link
Author

yes, only on simulator. Although it doesn't crush on real device, but it doesn't work well with UIPageViewController. I have a pageVC that shows three pages, camera is one of them, when swipe to switch pages UI will pause for a second then switch.

@remirobert
Copy link
Owner

That's strange. So first the crash on the simulator is "normal". I mean I can also avoid it.
For the second point that's strange. Probably you can start the camera engine, in the AppDelegate.

CameraEngine.startup()

@Jackson0111
Copy link
Author

On a real device, it only freezes the UI on the first swipe, after that everything works smoothly.

@remirobert
Copy link
Owner

Yes ok ! That's because the camera engine in the very first time, is begin to start.
So move the start in the AppDelegate, and everything, will works as expected.

@Jackson0111
Copy link
Author

Perfect!!! Thanks! I really love this thing it's simple and great

@remirobert
Copy link
Owner

Awesome thanks !.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants