blog
Ottorino Bruni  

How to Take a Screenshot or Record a Video using the iOS Simulator

As an iOS  to show my project or to publish an app on the AppStore I need to take screenshots or to record a video.

The first idea was to use the Simulator and press the button Save Screen when i need, for the video to use QuickTime Player, you can follow this link to understand how to do.

I’ve been using the xcrun command for some time and now I feel comfortable with it. You can automate it by creating a script.

What is xcrum command ?

xcrun is a tool provided by Apple to run any tool inside Xcode from the command line, usually it’s available with the installation of xcode but you can get downloading the Command Line Tools package from the Developer website. The Command Line Tools package is available for download on the Download for Apple Developers page. Log in with your Apple ID, then search and download the Command Line Tools package appropriate for your machine

How to Take a Screenshot with xcrum ?

  1. Run your app in the Simulator.
  2. Launch Terminal.app (in /Applications/Utilities) and run this command:
xcrun simctl io booted screenshot screenshot.png
xcrun simctl io booted screenshot screenshot.png

There are several option to use with this command to improve your screenshot:

  • –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
    • You may also specify a port by UUID. 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.

How to Record a Video with xcrum ?

  1. Run your app in the Simulator.
  2. Launch Terminal.app (in /Applications/Utilities) and run this command:
xcrun simctl io booted recordVideo video.mov

There are several option to use with this command to improve your video:

  • –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.

 

If you think your friends/network would find this useful, please share it with them. I’d really appreciate it.

Thanks for reading! ????

Leave A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.