Test in App Screenshot for iOS/iPadOS
- A
UIGraphicsImageRenderer
object is created with the bounds of the current view. - The
image(actions:)
method is called on the renderer object. This method takes a closure, where you callrender(in:)
on the view's layer, passing thecgContext
of the image renderer context. - This will create an image of the view's layer, effectively taking a screenshot.
- The screenshot is then saved to the photo library with
UIImageWriteToSavedPhotosAlbum()
. - As before, you need to have the
NSPhotoLibraryAddUsageDescription
key in yourInfo.plist
to get the user's permission to save photos to the photo library.