title: No depthData with iPhone X, iPhone XS is fine
body: <p>I am not getting <code>depthData</code> when I take a photo on an iPhone X the first time I take a picture.</p>
  
  <p>Camera permissions are valid</p>
  
  <p>If I run the code on the <strong>iPhone X</strong>, take a picture, no depth data, if I tap again, I get depth data. If I add a delay before I call <code>capturePhoto</code> then I do get <code>depthData</code></p>
  
  <p>If I run the code on the <strong>iPhone XS</strong>, take a picture, I have depth data straight away</p>
  
  <p>Is there something I'm missing with my code?</p>
  
  <pre><code>import UIKit
  import AVFoundation
  import os.log
  
  extension OSLog {
      /// The subsystem for the app
      public static var appSubsystem = "com.my.app"
      /// Image processing category
      static let imageService = OSLog(subsystem: OSLog.appSubsystem, category: "Image")
  }
  
  /**
   Use this as a logging system, it's compiled out for release builds for now.
   */
  func DLog(_ string: String, subsystem: OSLog, type: OSLogType = .debug) {
      #if DEBUG
      os_log("%{PUBLIC}@", log: subsystem, type: type, string)
      #endif
  }
  
  class ViewController: UIViewController {
  
      var photoProcessingQueue = DispatchQueue(label: "ProcessingQueue", attributes: [], autoreleaseFrequency: .workItem)
  
      var photoCaptureOutput: AVCapturePhotoOutput!
      var photoSession: AVCaptureSession!
      var initalized: Bool = false
  
      func setupCaptureSession() {
  
          defer {
              photoSession.commitConfiguration()
          }
  
          photoCaptureOutput = AVCapturePhotoOutput()
          photoSession = AVCaptureSession()
  
          DLog("setupCaptureSession \(String(describing: Thread.current))", subsystem: .imageService)
  
          photoSession.beginConfiguration()
          photoSession.sessionPreset = .photo
  
          do {
  
              guard let defaultCaptureDevice = AVCaptureDevice.default(.builtInDualCamera, for: .video, position: .back) else {
                  DLog("can't find camera", subsystem: .imageService, type: .error)
                  return
              }
  
              let videoDeviceInput = try AVCaptureDeviceInput(device: defaultCaptureDevice)
  
              if photoSession.canAddInput(videoDeviceInput) {
                  photoSession.addInput(videoDeviceInput)
              } else {
                  DLog("can't add camera", subsystem: .imageService, type: .error)
                  return
              }
  
              if photoSession.canAddOutput(photoCaptureOutput) {
                  photoSession.addOutput(photoCaptureOutput)
  
                  photoCaptureOutput.isHighResolutionCaptureEnabled = true
                  photoCaptureOutput.isDepthDataDeliveryEnabled = photoCaptureOutput.isDepthDataDeliverySupported
                  photoCaptureOutput.maxPhotoQualityPrioritization = .quality
              } else {
                  DLog("Could not add photo output to the session", subsystem: .imageService, type: .error)
              }
  
          } catch {
  
              DLog("general camera error: \(error)", subsystem: .imageService, type: .error)
          }
  
      }
  
      @IBAction func takePhoto(sender: UIButton) {
          photoProcessingQueue.async {
  
              if !self.initalized {
                  self.setupCaptureSession()
                  self.initalized = true
              }
  
              DLog("Photo session running: \(self.photoSession.isRunning) \(String(describing: Thread.current))", subsystem: .imageService)
              self.photoSession.startRunning()
              DLog("Photo session running: \(self.photoSession.isRunning) \(String(describing: Thread.current))", subsystem: .imageService)
  
              let photoSettings: AVCapturePhotoSettings
              if self.photoCaptureOutput.availablePhotoCodecTypes.contains(.jpeg) {
                  photoSettings = AVCapturePhotoSettings(format: [AVVideoCodecKey: AVVideoCodecType.jpeg])
              } else {
                  photoSettings = AVCapturePhotoSettings()
              }
  
              photoSettings.flashMode = .auto
              photoSettings.isDepthDataDeliveryEnabled = self.photoCaptureOutput.isDepthDataDeliverySupported
              photoSettings.photoQualityPrioritization = .quality
  
              // BUG iPhone X returns no depthData without a delay here...
              //Thread.sleep(forTimeInterval: 0.1)
  
              // Actually capture photo
              self.photoCaptureOutput.capturePhoto(with: photoSettings, delegate: self)
          }
      }
  }
  
  extension ViewController : AVCapturePhotoCaptureDelegate {
      func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
          DLog("photo.depthData?.depthDataMap: \(photo.depthData?.depthDataMap)", subsystem: .imageService)
      }
  }
  </code></pre>