Test in App Screenshot for iOS/iPadOS
- A
UIGraphicsImageRendererobject 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 thecgContextof 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
NSPhotoLibraryAddUsageDescriptionkey in yourInfo.plistto get the user's permission to save photos to the photo library.