title: How do I capture still photographs in a RealityKit app?
body: <p>I have an augmented reality app built using RealityKit in Swift 5. I would like to capture a RAW image of the underlying scene (without virtual objects). I am running the code below, however it never captures any photos but gives me an error message that says &quot;Cannot Record&quot;. The documentation is somewhat scant on this, so any help would be appreciated.</p>
  <pre><code>import Foundation
  import AVFoundation
  
  
  
  class CapturePhoto: NSObject, AVCapturePhotoCaptureDelegate{
      
  
  
      
      var capture = AVCapturePhotoOutput()
      var availableCameraSettings: Array&lt;AVCapturePhotoSettings&gt; = []
      var session = AVCaptureSession()
      
      let prompt = Prompt()
  
      override init(){
          
          super.init()
   
          createSettings()
          configOutput()
          configSession()
          startSesssion()
   
          // do any other config here
          
      }
      
      func configOutput(){
          capture.isHighResolutionCaptureEnabled = true
          capture.setPreparedPhotoSettingsArray( availableCameraSettings, completionHandler: nil )
      }
      
     
      
      func configSession(){
          
          session.stopRunning()
          session.beginConfiguration()
          
          session.sessionPreset = .photo
          
          let input = try? AVCaptureDeviceInput( device: getDevice() )
   
          if( session.canAddOutput( capture ) ){
              session.addOutput( capture )
          }
          
          if ( session.canAddInput( input! ) ){
              session.addInput( input! )
          }
          
          session.commitConfiguration()
          
      }
      
      func startSesssion(){
          session.startRunning()
      }
      
      func stopSession(){
          session.stopRunning()
      }
      
      func getDevice() -&gt; AVCaptureDevice{
  
          if let device = AVCaptureDevice.default(.builtInWideAngleCamera,
                                                  for: .video, position: .back) {
              return device
          } else {
              fatalError(&quot;Missing expected back camera device.&quot;)
          }
      }
      
      func getBestSettings() -&gt; AVCapturePhotoSettings{
          return AVCapturePhotoSettings( /*    rawPixelFormatType: 0 */ )
      }
  
      
      func createSettings(){
          
          let settings = getBestSettings()
          settings.flashMode = .on
          if #available(iOS 14.1, *) {
              settings.isAutoContentAwareDistortionCorrectionEnabled = false
          } 
          settings.isAutoRedEyeReductionEnabled = false
          settings.isCameraCalibrationDataDeliveryEnabled = false
          settings.isHighResolutionPhotoEnabled = false
          settings.isPortraitEffectsMatteDeliveryEnabled = false
          
          availableCameraSettings.append( settings )
          let ditto = AVCapturePhotoSettings( from: settings )
          ditto.flashMode = .off
          availableCameraSettings.append( ditto )
      }
  
      func captureImage()
      {
          for setting in availableCameraSettings{
  
              let settings = AVCapturePhotoSettings( from: setting )
              capture.capturePhoto(with: settings, delegate: self )
  
          }
  
      }
      
      func photoOutput(_ output: AVCapturePhotoOutput,
       didFinishProcessingPhoto photo: AVCapturePhoto,
       error: Error?)
      {
          if error != nil {
              print( error!.localizedDescription )
              prompt.prompt ( Info( error!.localizedDescription, 0 ) )
          } else{
              print( photo.timestamp )
              print ( ( photo.isRawPhoto ? &quot; Raw&quot; : &quot; Not raw&quot; ) + &quot;\n&quot; )
              DispatchQueue.global( qos: .background ).async {
                  AudioServicesPlaySystemSound( 1108 )
              }
          }
  
      }
  
  
  
  }
  
  </code></pre>