1. 程式人生 > >終端:Xcode模擬器上安裝.app方法

終端:Xcode模擬器上安裝.app方法

前言

有的時候,我們可能需要將別人的Xcode執行之後的程式包(xxx.app)安裝在自己的模擬器上,如下我將介紹如何通過終端來安裝。

實現

獲取自己Xcode生成的xxx.app

steps 1:在工程 didFinishLaunchingWithOptions: 方法中列印bundle路徑:

NSLog(@"%@", [[NSBundle mainBundle] pathForAuxiliaryExecutable:@""]);

steps 2:拷貝列印的bundle路徑,然後點選桌面->選擇螢幕上方工具欄上的前往->選擇前往資料夾:

這裡寫圖片描述

steps 3:將拷貝的路徑貼上在前往資料夾路徑中,點選回車即可:

這裡寫圖片描述

安裝別人Xcode生成的xxx.app

steps 1:開啟終端

這裡寫圖片描述

steps 2:在終端輸入xcrun simctl install booted xxx.app路徑,點選回車。注意,xxx.app路徑為你需要安裝到模擬器中的app的路徑,獲取方法直接將其拖入終端即可。這裡有個小技巧,可先複製 xcrun simctl install booted 貼上到終端,然後再將xxx.app拖入到終端,兩者之間以空格隔開。

Tips

如果沒有安裝Command Line Tool,系統會自動提示安裝,點選install即可。

異常問題

1、xcrun simctl install booted /path/xxx.app

2、xcrun: error: unable to find utility “simctl”, not a developer tool or in PATH`
xcrun simctl install booted /path/xxx.app

3、xcrun: error: active developer path (“/Volumes/Xcode/Xcode.app/Contents/Developer”) does not exist, use xcode-select –switch path/to/Xcode.app to specify the Xcode that you wish to use for command line developer tools (or see

man xcode-select)
No devices are booted`

這些問題將會導致安裝不成功,如果沒有安裝上可執行下面的操作。

解決方案

steps 1:獲取Xcode路徑。獲取Xcode路徑只需到應用程式中找到Xcode,然後將其拖入到終端即可獲取到Xcode的路徑。

steps 2:在終端中繼續輸入 sudo xcode-select -switch Xcode路徑/Contents/Developer 即可。

Tips

比如我的Xcode路徑為:/Applications/Xcode.app。那麼我在終端中則會輸入為:sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer