iosshcalabash-ios

How to get AppID of my application to access application data folder in iOS simulator?


I am building Cucumber/Calabash tests for my iOS app. I need to access my application data folder in simulator, to copy data to that folder. I can get to this path:

~/Library/Developer/CoreSimulator/Devices/[DeviceID]/data/Containers/Data/Application/[NEED TO GET THIS AppID]

But I need to detect my [AppID] to access the right folder. Is there any method to get it from application name or bundle id via terminal or using some .sh scripts?


Solution

  • I have solved this with using script like this:

    APPLICATION_DATA_FOLDER = $1
    cd APPLICATION_DATA_FOLDER
    
    for dir in *
    do
     IDENTIFIER=$(/usr/libexec/PlistBuddy -c "print :MCMMetadataIdentifier" ${dir}/.com.apple.mobile_container_manager.metadata.plist)
     if [ "${IDENTIFIER}" == "YOUR APPNAME HERE" ]; then
      cd -
      echo "${APPLICATION_DATA_FOLDER}/${dir}"
      exit 0
     fi
    done
    

    I am passing application data folder as path - this:

    ~/Library/Developer/CoreSimulator/Devices/[DeviceID]/data/Containers/Bundle/Application/
    

    The script goes through the .plist files in folders and tries to match my Application name