修改已经启动的模拟器的状态栏的时间、电量、运营商、信号强度等,一般提供审核截图时用
ruby 脚本内容如下
require 'json'
devices_json = `xcrun simctl list --json devices available booted`
devices_json_obj = JSON.parse(devices_json)
devices_json_obj['devices'].each do |_key, value|
next unless value.is_a?(Array)
value.each do |device_info|
cmd = "xcrun simctl status_bar #{device_info['udid']} override --time \"9:41\" --batteryState charged --batteryLevel 100 --dataNetwork wifi --operatorName '移动5G' --batteryState discharging --wifiBars 3 --wifiMode active --cellularMode active --cellularBars 4 --batteryLevel 100"
puts cmd
puts `
end
end
列出当前启动的模拟器的信息xcrun 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.
修改状态栏的命令xcrun 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.