title: Why does the screenshot show just white when I'm trying to take a screenshot of my app programmatically in Swift?
body: <p>On my app, I have a view which holds a camera. I want to take a screenshot of this view which holds the camera. However when I do this with the following code:</p>
  
  <pre><code>let layer = UIApplication.sharedApplication().keyWindow!.layer
  let scale = UIScreen.mainScreen().scale
  UIGraphicsBeginImageContextWithOptions(layer.frame.size, false, scale);
  
  layer.renderInContext(UIGraphicsGetCurrentContext()!)
  let screenshot = UIGraphicsGetImageFromCurrentImageContext()
  UIGraphicsEndImageContext()
  
  UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil)
  </code></pre>
  
  <p>the screenshot which was saved to photos is just blank and doesn't show the camera view.</p>