Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

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! ????

🚀 Discover CodeSwissKnife, your all-in-one, offline toolkit for developers!

Click to explore CodeSwissKnife 👉

Leave A Comment

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