iosswiftuigraphicscontextios13

Save image to Photos app in Simulator - Generate screenshot in iOS 13


Edit

Original:

How do you create an image from what is on the screen in iOS 13?

In iOS 12, this code worked:

UIGraphicsBeginImageContextWithOptions(view.frame.size, false, 0.0)
view.drawHierarchy(in: view.frame, afterScreenUpdates: true)
let myImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()

But in Xcode 11 using iOS 13 simulators, it generates a pixelated image with some text:

enter image description here

Anyone know what should be changed? Xcode 11 appears to be running the same Swift version as Xcode 10.2 (Swift 5).


Solution

  • This bug seems fixed in iOS 13 Developer Beta 2 / Xcode 11 beta 2.

    Xcode 11.0 beta 2 (11M337n)
    iOS 13.0 (17A5508l)