xcodeshellbuildbuild-settingsxcode-build-settings

How to check type of device (device/simulator) on Run Script phase in Build Settings?


I have 2 versions of some library, one - for real device, other - for simulator. Can I write sh script to detect on which device (device/sim) Xcode will run application and switch that libraries in Run Script phase?


Solution

  • When your script executed list of environment variables available. One of them is __IS_NOT_SIMULATOR.

    When building for simulator it have this value:

    export __IS_NOT_SIMULATOR\=NO
    

    When building for device it have this value:

    export __IS_NOT_SIMULATOR\=YES
    

    In build script it can be accessed like this:

    echo "IS_NOT_SIMULATOR = ${__IS_NOT_SIMULATOR}"