Modify the time, power, carrier, signal strength, etc., in the status bar of the simulator that has been started, which is generally used for reviewing screenshots

The Ruby script reads as follows

# frozen_string_literal: true

require 'json'

devices_json = `xcrun simctl list --json devices available booted`
# puts devices_json
devices_json_obj = JSON.parse(devices_json)
devices_json_obj['devices'].each do|_key, value| next unless value.is_a? (Array) value.eachdo |device_info|
    cmd = "xcrun simctl status_bar #{device_info['udid']} override --time \"9:41\" --batteryState charged --batteryLevel 100 --dataNetwork WIFI --operatorName 'MOBILE 5G' --batteryState Wind --wifiBars 3 --wifiMode Active --cellularMode Active  --cellularBars 4 --batteryLevel 100"
    puts cmd
    puts `#{cmd}`
  end
end
Copy the code

Lists information about the currently started emulatorxcrun simctl help list

 List available devices, device types, runtimes, or device pairs.
 Usage: simctl list [-j | --json] [-v] [devices|devicetypes|runtimes|pairs] [<search term>|available]
 -j     Print as JSON
 -v     More verbose output

 Specify one of 'devices'.'devicetypes'.'runtimes', or 'pairs' to list only items of that type. If a type filter is specified you may also specify a search term. Search terms use a simple case-insensitive contains check against the item's description. You may use the search term 'available' to only list available items.
Copy the code

Command to modify the status barxcrun simctl help status_bar


 Set or clear status bar overrides
 Usage: simctl status_bar <device> [list | clear | override <override arguments>]
 
 Supported Operations:
     list
   List existing overrides.
 
     clear
   Clear all existing status bar overrides.
 
     override <override arguments>
   Set status bar override values, according to these flags.
   You may specify any combination of these flags (at least one is required):
 
   --time <string>
        Set the date or time to a fixed value.
        If the string is a valid ISO date string it will also set the date on relevant devices.
   --dataNetwork <dataNetworkType>
        If specified must be one of 'wifi'.'3g'.'4g'.'lte'.'lte-a', or 'lte+'.
   --wifiMode <mode>
        If specified must be one of 'searching'.'failed', or 'active'.
   --wifiBars <int>
        If specified must be 0-3.
   --cellularMode <mode>
        If specified must be one of 'notSupported'.'searching'.'failed', or 'active'.
   --cellularBars <int>
        If specified must be 0-4.
   --operatorName <string>
        Set the cellular operator/carrier name. Use ' ' for the empty string.
   --batteryState <state>
        If specified must be one of 'charging'.'charged', or 'discharging'.
   --batteryLevel <int>
        If specified must be 0-100.
Copy the code