xcode 查找 iOS Simulator 应用程序的路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12675965/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 15:50:54  来源:igfitidea点击:

Finding the path of the iOS Simulator app

iosxcodexcode4.2ios-simulator

提问by Muthu

I want to run the simulatorfrom the command line. Is there any way to find the simulator paththrough command line. Apple frequently changes the simulator location like

我想从命令行运行模拟器。有什么办法可以通过命令行找到模拟器路径。Apple 经常更改模拟器位置,例如

/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app/Contents/MacOS/iPhone Simulator

/Applications ........ / IOS simulato....

Is there any way to find the simulator path from terminal. ?

有什么办法可以从终端找到模拟器路径。?

回答by AliSoftware

Here are two suggestions:

这里有两个建议:

  • You can use xcode-selectto print the path to Xcode:

    # This returns sthg like "/Applications/Xcode.app/Contents/Developer"
    XCODEPATH=$(xcode-select --print-path)
    # Then build the rest of the path to the simulator SDK
    SIMSDKPATH=${XCODEPATH}/Platforms/iPhoneSimulator.platform/Developer
    # And add the rest of the path to the Simulator app
    SIMULATORPATH=$(SIMSDK}/Applications/iPhone Simulator.app/Contents/MacOS/iPhone Simulator
    
  • You can use xcrunto find the path of a xcodebuild tool in the iphonesimulator SDK, then deducting the path from here:

    # This returns sthg like "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc"
    GCCPATH=$(xcrun -sdk iphonesimulator -find gcc)
    # Then go up 3 directories
    SIMSDKPATH=$(dirname $(dirname $(dirname ${GCCPATH})))
    # And down to the Simulator app
    SIMULATORPATH=${SIMSDKPATH}/Applications/iPhone Simulator.app/Contents/MacOS/iPhone Simulator
    
  • 您可以使用xcode-select打印 Xcode 的路径:

    # This returns sthg like "/Applications/Xcode.app/Contents/Developer"
    XCODEPATH=$(xcode-select --print-path)
    # Then build the rest of the path to the simulator SDK
    SIMSDKPATH=${XCODEPATH}/Platforms/iPhoneSimulator.platform/Developer
    # And add the rest of the path to the Simulator app
    SIMULATORPATH=$(SIMSDK}/Applications/iPhone Simulator.app/Contents/MacOS/iPhone Simulator
    
  • 可以使用xcrun在iphonesimulator SDK中找到xcodebuild工具的路径,然后从这里推导出路径:

    # This returns sthg like "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc"
    GCCPATH=$(xcrun -sdk iphonesimulator -find gcc)
    # Then go up 3 directories
    SIMSDKPATH=$(dirname $(dirname $(dirname ${GCCPATH})))
    # And down to the Simulator app
    SIMULATORPATH=${SIMSDKPATH}/Applications/iPhone Simulator.app/Contents/MacOS/iPhone Simulator