4

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?

sig
  • 6,024
  • 2
  • 26
  • 31
Jakub
  • 285
  • 4
  • 21

4 Answers4

2

In Swift 4, insert the following code inside viewDidLoad():

    let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) // get the Documents folder path
    
    let pathForDocumentDir = documentsPath[0]
    print("pathForDocumentDir: \(pathForDocumentDir)")

e.g.:

class ViewController: UIViewController {
    override func viewDidLoad() {
        let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) // get the Documents folder path
        
        let pathForDocumentDir = documentsPath[0]
        print("pathForDocumentDir: \(pathForDocumentDir)")
    }
}

This will print something like this in the Console output:

/Users/user/Library/Developer/CoreSimulator/Devices/11321A31-27D6-49E0-85C8-D7EDEFA6751F/data/Containers/Data/Application/BB9EAD09-17B5-4FA1-907A-0EDFC07BFA62/Documents

Code based on this source

itwebdeveloper
  • 699
  • 1
  • 7
  • 15
1

[[NSBundle mainBundle] bundlePath] will give you the top folder of your application. It will look something like this:

~/Library/Developer/CoreSimulator/Devices/[DeviceID]/data/Containers/Bundle/Application/[AppID]/[AppName.app]

Then you can get [AppID] using an NSArray:

NSArray *components = [path componentsSeparatedByString:@"/"];
NSLog(@"AppID: %@", [components objectAtIndex:[components count] - 2]);
CristiC
  • 22,068
  • 12
  • 57
  • 89
  • I have to access this via terminal comands... (used in .rb files of calabash tests) also my application is made with C# and Xamarin not in objective C or swift... I can get AppID in Containers/**Bundle**/Application/, via searching BundleName but that ID is different from AppID in Containers/**Data**/Application... – Jakub Feb 28 '17 at 10:54
1

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

Jakub
  • 285
  • 4
  • 21
0

I do it in 2 steps:

  1. Find OR add(save on simulator) some unique file. In my case it's file with .xlsx extension.
  2. Use script that can be run in terminal:

    cd ~/Library/Developer/CoreSimulator/Devices/[DeviceId] && find . -name '*.xlsx'

It returns path of found files where u can get appropriate application Id by using Regex for example:

./data/Containers/Shared/AppGroup/5BBE0D19-83A3-41D5-81DA-971CB547B9D0/File Provider Storage/test_pdf_file1578673688647.xlsx
dmytro Minz
  • 407
  • 1
  • 8
  • 19