命令行工具 Simulator control
命令的基本組成
xcrun simctl [subcommand] [<device>] [<subcommand option>] [<bundle identifier>] ...
[subcommand] 可以在終端中輸入:xcrun simctl --help
可以看到simctl包含的子命令
[<device>] 用來指定模擬器,可以填寫模擬器的UDID或者填寫booted
自動(dòng)選擇模擬器
[<subcommand option>] 在終端中輸入:xcrun simctl [subcommand]
可以看到某個(gè)子命令的功能說明净当、使用方法和用法示例
[<bundle identifier>] 一些子命令需要具體指定到某一個(gè)app
subcommand示例
如ui子命令内斯,在終端輸入xcrun simctl ui
會輸出如下信息:
說明:Get or Set UI options
使用方法:Usage: simctl ui <device> <option> [<arguments>]
用法示例:
appearance
When invoked without arguments prints the current user interface appearance style:
light
The Light appearance style.
dark
The Dark appearance style.
unsupported
The platform or runtime version do not support appearance styles.
unknown
The current style is unknown or there was an error detecting it.
在終端輸入xcrun simctl ui booted appearance dark
意為把模擬器切換為深色模式
一些常用的功能說明
privacy 隱私訪問權(quán)限調(diào)試
包含all, calendar ,contacts-limited, contacts 等子命令
以相冊訪問權(quán)限為例
獲取相冊權(quán)限:xcrun simctl privacy booted grant photos <bundle id>
撤銷相冊權(quán)限:xcrun simctl privacy booted revoke photos <bundle id>
重置相冊權(quán)限,下次調(diào)用時(shí)彈窗像啼, <bundle id>可不傳:xcrun simctl privacy booted reset photos <bundle id>
push推送調(diào)試
需要準(zhǔn)備一個(gè)json文件俘闯,要求必須包含aps字段,最大不超過4096字節(jié)
{
"Simulator Target Bundle": "bundle id",
"aps": {
"alert": {
"title": "主標(biāo)題",
"subtitle": "副標(biāo)題",
"body": "內(nèi)容"
}
}
}
使用時(shí)cd到j(luò)son文件所在目錄下忽冻,如json文件中包含Simulator Target Bundle
字段指明了bundle id真朗,則輸入命令可不指定bundle id,如未包含Simulator Target Bundle
字段僧诚,則需在命令中指定bundle id遮婶。
xcrun simctl push booted <json file name>
xcrun simctl push booted <bundle id> <json file name>
另外,如json文件中包含Simulator Target Bundle
字段指明了bundle id振诬,可直接拖拽json文件至模擬器蹭睡,無需輸入命令。
參考WWDC 20-10647