There would be a time when you need to capture your app screen or record a video of your app, whether for an App Store screenshot or an App Store preview video. You can do all of this without external tools.
For taking a screenshot, I usually launch an app in the Simulator and press ⌘ - command + s
or File > New Screen Shot
. The screenshot will be saved to your Desktop.
xcrun is a tool Apple provided to run any tool inside Xcode from the command line.
1- To take a screenshot with xcrun.
2- Run your app in the Simulator.
3- Open Terminal.app (located in /Applications/Utilities)
4- Enter the following command and hit ⏎ Return.
xcrun simctl io booted screenshot <file_name>.<file_extension>
The screenshot will be saved to your current directory. If you don't know where is the current directory, type pwd in Terminal.app and press ⏎ Return.
xcrun simctl io booted screenshot myScreenshot.png
You can specify the following options to the command.
--type
Can be "png", "tiff", "bmp", "gif", "jpeg". Default is png.--display
- iOS: supports "internal" or "external". Default is "internal".
- tvOS: supports only "external"
- watchOS: supports only "internal"
--mask
For non-rectangular displays, handle the mask by policy:- ignored: The mask is ignored and the unmasked framebuffer is saved.
- alpha: The mask is used as premultiplied alpha.
- black: The mask is rendered black.
The following example will take a jpeg screenshot with a mask (see round corners and a notch).
xcrun simctl io booted screenshot --type=jpeg --mask=black myScreenshot.jpeg
When it comes to recording a video, xcrun is an easy way for me (I used to record video with Quicktime, but I find it quite cumbersome).
1- Run your app in the Simulator.
2- Open Terminal.app (located in /Applications/Utilities)
3- Enter the following command and hit ⏎ Return.
xcrun simctl io booted recordVideo <file_name>.<file_extension>
4- Press ⌃ – control + c
to stop recording the video.
The video will be saved to your current directory. If you don't know where is the current directory, type pwd in Terminal.app and press ⏎ Return
.
xcrun simctl io booted recordVideo myVideo.mov
You can specify the following options to the command.
--codec
Specifies the codec type: "h264" or "hevc". Default is "hevc".--display
- iOS: supports "internal" or "external". Default is "internal".
- tvOS: supports only "external"
- watchOS: supports only "internal"
--mask
For non-rectangular displays, handle the mask by policy:- ignored: The mask is ignored and the unmasked framebuffer is saved.
- alpha: Not supported, but retained for compatibility; the mask is rendered black.
- black: The mask is rendered black.
--force
Force the output file to be written to, even if the file already exists.
xcrun simctl io booted recordVideo --code=h264 --mask=black --force myVideo.mov
All xcrun command might vary based on your Xcode and mac version. For more information, run this command:
xcrun simctl io help