title: iOS10, camera permission - black screen for "camera app"
body: <p>Of course with iOS 10, you now have to do THIS</p>
  
  <p><a href="https://i.stack.imgur.com/1cbVT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1cbVT.png" alt="enter image description here"></a></p>
  
  <p>to use the phone's camera.  On first launch, the user gets a question such as,</p>
  
  <p><a href="https://i.stack.imgur.com/cW0M7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cW0M7.png" alt="enter image description here"></a></p>
  
  <p>and all is well.</p>
  
  <p>BUT we have a client app that is a "camera app": when you launch the app <strong>it simply immediately launches the camera</strong>, when the app is running the camera is running and is shown fullscreen.  The code to do so is the usual way, see below.</p>
  
  <p>The problem is - the first launch of the app on a phone, the user is asked the question; user says yes.  But then, the camera is just black on devices we have tried.  It does not crash (as it would if you forget the plist item) but it goes black and stays black.</p>
  
  <p>If the user quits the app and launches it again - it's fine, everything works.</p>
  
  <p><strong>What the heck is the workflow for a "camera app"?</strong>  I can't see a good solution, but there must be one for the various camera apps out there - which immediately go to fullscreen camera when you launch the app.</p>
  
  <pre><code>class CameraPlane:UIViewController
      {
      ... 
      func cameraBegin()
          {
          captureSession = AVCaptureSession()
          captureSession!.sessionPreset = AVCaptureSessionPresetPhoto
  
          let backCamera = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)
  
          var error: NSError?
          var input: AVCaptureDeviceInput!
          do {
              input = try AVCaptureDeviceInput(device: backCamera)
              } catch let error1 as NSError
                  {
                  error = error1
                  input = nil
                  }
  
          if ( error != nil )
              {
              print("probably on simulator? no camera?")
              return;
              }
  
          if ( captureSession!.canAddInput(input) == false )
              {
              print("capture session problem?")
              return;
              }
  
          captureSession!.addInput(input)
  
          stillImageOutput = AVCaptureStillImageOutput()
          stillImageOutput!.outputSettings = [AVVideoCodecKey: AVVideoCodecJPEG]
  
          if ( captureSession!.canAddOutput(stillImageOutput) == false )
              {
              print("capture session with stillImageOutput problem?")
              return;
              }
  
          captureSession!.addOutput(stillImageOutput)
          previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
          previewLayer!.videoGravity = AVLayerVideoGravityResizeAspectFill
                                          // or, AVLayerVideoGravityResizeAspect
  
          fixConnectionOrientation()
  
          view.layer.addSublayer(previewLayer!)
          captureSession!.startRunning()
          previewLayer!.frame = view.bounds
          }
  </code></pre>