Take a screenshot
source link: https://sarunw.com/posts/take-screenshot-and-record-video-in-ios-simulator/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Take a screenshot and record a video in iOS Simulator
Table of Contents
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.
Take a screenshot
An easy way
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
xcrun is a tool Apple provided to run any tool inside Xcode from the command line.
- To take a screenshot with xcrun.
- Run your app in the Simulator.
- Open Terminal.app (located in /Applications/Utilities)
- 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.
Example
xcrun simctl io booted screenshot myScreenshot.png
Options
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.
Example
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
Record a video
Xcrun
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).
- Run your app in the Simulator.
- Open Terminal.app (located in /Applications/Utilities)
- Enter the following command and hit ⏎ Return.
xcrun simctl io booted recordVideo <file_name>.<file_extension>
- 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.
Example
xcrun simctl io booted recordVideo myVideo.mov
Options
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.
Example
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
Related Resources
Building from the Command Line with Xcode FAQ
You may also like
Xcode 12.5 brings many great updates and features. One of them is the ability to record a video of the app directly from the Simulator app.
Simulator VideoIn the past, the way I test a custom URL scheme is to go to Safari and open up any of my custom URLs. If you are still doing that, there is a better alternative.
SimulatorRead more article about Simulator, Video, Screenshot,
or see all available topic
Get new posts weekly
If you enjoy this article, you can subscribe to the weekly newsletter.
Every Friday, you’ll get a quick recap of all articles and tips posted on this site — entirely for free.
Feel free to follow me on Twitter and ask your questions related to this post. Thanks for reading and see you next time.
If you enjoy my writing, please check out my Patreon https://www.patreon.com/sarunw and become my supporter. Sharing the article is also greatly appreciated.
UINavigationBar changes in iOS13, Part2: UISearchController
Revisit of navigation bar appearance — this time with a UISearchController. If you have a search bar in your navigation bar, you might need to recheck when you build your app against iOS13.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK