[Thera] 關(guān)于iOS模擬器的知識點

為什么Thera需要iOS模擬器伐庭?

因為想為動態(tài)方案編寫打造原生開發(fā)體驗。
在Thera環(huán)境中分冈,點擊運行拉起模擬器和喚醒預(yù)覽圾另,這一切就跟使用Xcode 編寫自己的Native App一樣。再配合hot-reload技術(shù),實時響應(yīng)渲染你正在編寫的weex動態(tài)語言代碼文件雕沉。不需要重新編譯集乔、鏈接、打包坡椒,所見即所得扰路。開發(fā)效率得到了真正的提高

另外 在iOS自動化測試中,不同分辨率/不同系統(tǒng)版本等客觀條件要求的測試環(huán)境對企業(yè)是不小的負(fù)擔(dān)倔叼。然而模擬器沒有這種問題汗唱,你可以任意創(chuàng)建iPhone4/iPhone5/iPhone6/iPhone 6 Plus等,然后指定內(nèi)部運行的系統(tǒng)版本是iOS8缀雳、iOS9還是最新的iOS10.3等等渡嚣。。

 ~ xcrun simctl 
usage: simctl [--noxpc] [--set <path>] [--profiles <path>] <subcommand> ...
       simctl help [subcommand]
Command line utility to control the Simulator

For subcommands that require a <device> argument, you may specify a device UDID
or the special "booted" string which will cause simctl to pick a booted device.
If multiple devices are booted when the "booted" device is selected, simctl
will choose one of them.

Subcommands:
    create              Create a new device.
    clone               Clone an existing device.
    upgrade             Upgrade a device to a newer runtime.
    delete              Delete a device or all unavailable devices.
    pair                Create a new watch and phone pair.
    unpair              Unpair a watch and phone pair.
    pair_activate       Set a given pair as active.
    erase               Erase a device's contents and settings.
    boot                Boot a device.
    shutdown            Shutdown a device.
    rename              Rename a device.
    getenv              Print an environment variable from a running device.
    openurl             Open a URL in a device.
    addmedia            Add photos, live photos, or videos to the photo library of a device.
    install             Install an app on a device.
    uninstall           Uninstall an app from a device.
    get_app_container   Print the path of the installed app's container
    launch              Launch an application by identifier on a device.
    terminate           Terminate an application by identifier on a device.
    spawn               Spawn a process on a device.
    list                List available devices, device types, runtimes, or device pairs.
    icloud_sync         Trigger iCloud sync on a device.
    pbsync              Sync the pasteboard content from one pasteboard to another.
    pbcopy              Copy standard input onto the device pasteboard.
    pbpaste             Print the contents of the device's pasteboard to standard output.
    help                Prints the usage for a given subcommand.
    io                  Set up a device IO operation.
    diagnose            Collect diagnostic information and logs.
    logverbose          enable or disable verbose logging for a device

Thera 項目中關(guān)于iOS模擬器的運用肥印,都是基于Apple Xcode提供的CLIxcrun下的子命令simctl

常用的幾個命令是 :

list

加-j參數(shù)识椰,會以JSON的數(shù)據(jù)形式輸出。方便程序處理

{
        "state" : "Shutdown",
        "availability" : "(available)",
        "name" : "iPhone 5",
        "udid" : "C0A814A0-C5C1-49E8-97EB-1E4607A08B37"
}

這里面最值得注意的就是 udid深碱,因為下面的啟動操作是和這個設(shè)備標(biāo)識符關(guān)聯(lián)的

boot

使用xcrun simctl list獲取設(shè)備UDID之后腹鹉,可以啟動模擬器。這個命令有一些問題:比如不能正常前臺拉起模擬器敷硅」χ洌可以使用Simulator.app 前臺打開:
open -n /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app --args -currentDeviceUDID C0A814A0-C5C1-49E8-97EB-1E4607A08B37

install

Usage: simctl install <device> <path>

喚起模擬器之后,可以將自己的應(yīng)用裝載到模擬器中绞蹦。
xcrun simctl install booted /Users/guomiaoyou/Library/Developer/Xcode/DerivedData/Tmall4iPhone-dwqfxitnjawridavpwanbryizslt/Build/Products/Debug-iphonesimulator/Tmall4iPhone.app

launch

Usage: simctl launch [-w | --wait-for-debugger] [--console] [--stdout=<path>] [--stderr=<path>] <device> <app identifier> [<argv 1> <argv 2> ... <argv n>]

--console Block and print the application's stdout and stderr to the current terminal.
Signals received by simctl are passed through to the application.(Cannot be combined with --stdout or --stderr)
--stdout=<path> Redirect the application's standard output to a file.
--stderr=<path> Redirect the application's standard error to a file.
Note: Log output is often directed to stderr, not stdout.

喚起模擬器中的App力奋,靠的是使用com.taobao.tmall 這個application bundle identifier
xcrun simctl launch booted com.taobao.tmall

這個命令還可以設(shè)置應(yīng)用控制臺的輸出out 和 錯誤err兩個通道重定向到日志文件中,不設(shè)置path則直接命令行控制臺打出幽七。

也可以傳入一些啟動參數(shù) xcrun simctl launch booted com.taobao.tmall -DumplingsPort 7001景殷。對應(yīng)的客戶端應(yīng)用獲取參數(shù)邏輯是:

 [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
            if([key isEqualToString:@"DumplingsPort"]){
                port = obj;
                *stop = YES;
            }
}];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子猿挚,更是在濱河造成了極大的恐慌咐旧,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,496評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件绩蜻,死亡現(xiàn)場離奇詭異铣墨,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)办绝,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,407評論 3 392
  • 文/潘曉璐 我一進(jìn)店門伊约,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人八秃,你說我怎么就攤上這事碱妆。” “怎么了昔驱?”我有些...
    開封第一講書人閱讀 162,632評論 0 353
  • 文/不壞的土叔 我叫張陵疹尾,是天一觀的道長。 經(jīng)常有香客問我骤肛,道長纳本,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,180評論 1 292
  • 正文 為了忘掉前任腋颠,我火速辦了婚禮繁成,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘淑玫。我一直安慰自己巾腕,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,198評論 6 388
  • 文/花漫 我一把揭開白布絮蒿。 她就那樣靜靜地躺著尊搬,像睡著了一般。 火紅的嫁衣襯著肌膚如雪土涝。 梳的紋絲不亂的頭發(fā)上佛寿,一...
    開封第一講書人閱讀 51,165評論 1 299
  • 那天,我揣著相機(jī)與錄音但壮,去河邊找鬼冀泻。 笑死,一個胖子當(dāng)著我的面吹牛蜡饵,可吹牛的內(nèi)容都是我干的弹渔。 我是一名探鬼主播,決...
    沈念sama閱讀 40,052評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼溯祸,長吁一口氣:“原來是場噩夢啊……” “哼捞附!你這毒婦竟也來了巾乳?” 一聲冷哼從身側(cè)響起您没,我...
    開封第一講書人閱讀 38,910評論 0 274
  • 序言:老撾萬榮一對情侶失蹤鸟召,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后氨鹏,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體欧募,經(jīng)...
    沈念sama閱讀 45,324評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,542評論 2 332
  • 正文 我和宋清朗相戀三年仆抵,在試婚紗的時候發(fā)現(xiàn)自己被綠了跟继。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,711評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡镣丑,死狀恐怖舔糖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情莺匠,我是刑警寧澤金吗,帶...
    沈念sama閱讀 35,424評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站趣竣,受9級特大地震影響摇庙,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜遥缕,卻給世界環(huán)境...
    茶點故事閱讀 41,017評論 3 326
  • 文/蒙蒙 一卫袒、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧单匣,春花似錦夕凝、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,668評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至虎忌,卻和暖如春泡徙,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背膜蠢。 一陣腳步聲響...
    開封第一講書人閱讀 32,823評論 1 269
  • 我被黑心中介騙來泰國打工堪藐, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人挑围。 一個月前我還...
    沈念sama閱讀 47,722評論 2 368
  • 正文 我出身青樓礁竞,卻偏偏與公主長得像,于是被迫代替她去往敵國和親杉辙。 傳聞我的和親對象是個殘疾皇子模捂,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,611評論 2 353

推薦閱讀更多精彩內(nèi)容