有的時候,我們可能需要將別人的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拖入到終端,兩者之間以空格隔開。
二,建議
如果沒有安裝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, usexcode-select –switch path/to/Xcode.app to specify the Xcode that you wish to use for command line developer tools (or seeman 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