ChatGPT解决这个技术问题 Extra ChatGPT

Xcode 6 iPhone Simulator Application Support location

In Xcode 6, I have an app I'm using Core Data in, but there is no folder in Application Support for the iOS 8 iPhone Simulator. Where are my files and Core Data sqlite database being stored?

Try this. There is an app which directly opens the Documents directory of the latest app run.
I added an answer (at the bottom of the other answers) that shows how to programmatically get the path where the Core Data files reside.
Have a look to this link..stackoverflow.com/questions/24133022/…
Use "NSTemporaryDirectory ()". Look this- stackoverflow.com/questions/1108076/…

S
Scott Gardner

The simulator directory has been moved with Xcode 6 beta to...

~/Library/Developer/CoreSimulator

Browsing the directory to your app's Documents folder is a bit more arduous, e.g.,

~/Library/Developer/CoreSimulator/Devices/4D2D127A-7103-41B2-872B-2DB891B978A2/data/Containers/Data/Application/0323215C-2B91-47F7-BE81-EB24B4DA7339/Documents/MyApp.sqlite

this is correct in general but it seems there are more internal folder changes. This is the path that works for me in Xcode Beta 3: ~/Library/Developer/CoreSimulator/Devices/B2C6629C-998D-4E84-9ADB-06CAF5BA4B89/data/Containers/Data/Application/62593001-FADA-4647-AA80-FE9973956C05/Documents/
Is there a way to understand that numbers or brute force is the only chance to get to data?
NSLog(@"app dir: %@",[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]); - will print the full path to data folder
I needed a persistent shortcut to my app's documents directory, for quick debugging. After application didFinishLaunchingWithOptions. #if DEBUG NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"]; NSString *aliasPath = [NSString stringWithFormat:@"XCodePaths/%@", appName]; remove([aliasPath UTF8String]); [[NSFileManager defaultManager]createSymbolicLinkAtPath:aliasPath withDestinationPath:DOCS_DIR error:nil]; #endif Now I've got a simlink that works, even though iOS8 + XCode6 changes my App's Data GUID everytime I build.
The xcrun simctl list command can be used to see the correspondence between the simulator names and the device UDIDs. Or more specifically the xcrun simctl list devices command.
u
ucangetit

I would suggest that you use SimPholders to find your Simulator files. It is a menu bar item that tracks your simulator apps and lets you go directly to their folders and content. It's awesome.


I was also having issues with SimPholders2 on Yosemite, so I started a command line script to help you find and open a Finder window to the simulator and App you want. It goes through the folders and metadata plists to list all simulator folders and Apps. If interested, check it out here
SimPholders2 works in Yosemite but it's a bit slow; once you click the icon in the status bar, just wait a few seconds and it should appear.
Whoa it's awesome and latest works with Yosemite + Xcode 6.3!
A
Amar

I found SimulatorManager application very useful. It takes you directly to the application folder of installed simulators. I have tried with 7.1, 8.0 and 8.1 simulators.

SimulatorManager resides as an icon in the system tray and provides an option to "Launch At Login".

https://i.stack.imgur.com/FkpZR.png

Note: This works only with Xcode 6 (6.1.1 in my case) and above.

Hope that helps!


Amar, how do you install the SimulatorManager? I thought it was a plugin to Xcode but it is an Xcode project
in the top bar select: Product -> Archive -> and then Export the Archive as a Mac Application without re-signing (the last option) you will get a .app file which you can put in your Application folder like a normal application...
h
himan

To know where your .sqlite file is stored in your AppDelegate.m add the following code

- (NSURL *)applicationDocumentsDirectory
{
    NSLog(@"%@",[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory      inDomains:NSUserDomainMask] lastObject]);

    return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory     inDomains:NSUserDomainMask] lastObject];
 }

now call this method in AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

  //call here
   [self applicationDocumentsDirectory];

}

great.. specially useful when there are multiple simulators
N
Nate Uni

This worked for me in swift:

let dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
println("App Path: \(dirPaths)")

s
seabass

I wrestled with this for some time. It became a huge pain to simply get to my local sqlite db. I wrote this script and made it a code snippet inside XCode. I place it inside my appDidFinishLaunching inside my appDelegate.


//xcode 6 moves the documents dir every time. haven't found out why yet. 

    #if DEBUG 

         NSLog(@"caching documents dir for xcode 6. %@", [NSBundle mainBundle]); 

         NSString *toFile = @"XCodePaths/lastBuild.txt"; NSError *err = nil; 

         [DOCS_DIR writeToFile:toFile atomically:YES encoding:NSUTF8StringEncoding error:&err]; 

         if(err) 
            NSLog(@"%@", [err localizedDescription]);

         NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];   

         NSString *aliasPath = [NSString stringWithFormat:@"XCodePaths/%@", appName]; 

         remove([aliasPath UTF8String]); 

         [[NSFileManager defaultManager] createSymbolicLinkAtPath:aliasPath withDestinationPath:DOCS_DIR error:nil]; 

     #endif

This creates a simlink at the root of your drive. (You might have to create this folder yourself the first time, and chmod it, or you can change the location to some other place) Then I installed the xcodeway plugin https://github.com/onmyway133/XcodeWay

I modified it a bit so that it will allow me to simply press cmd+d and it will open a finder winder to my current application's persistent Documents directory. This way, not matter how many times XCode changes your path, it only changes on run, and it updates your simlink immediately on each run.

I hope this is useful for others!


Thanks, I just update XcodeWay to support iOS 8 simulator folder
N
Nagarjun

Open finder>Library>Developer>CoreSimulator>Devices

Then Change Arrangement icon from finder select Date Added

Select your app >data>Container>data>Applications>

choose your app >Documents>Here is your db file

In my case:

/Users/pluto/Library/Developer/CoreSimulator/Devices/A75107D2-A535-415A-865D-978B2555370B/data/Containers/Data/Application/265A12BC-FF5B-4235-B5EF-6022B83754B4/Documents/dboPhotoBucket.sqlite

Otherwise do this :

NSLog(@"app dir: %@",[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]); 

- It will print the full path to data folder.

Swift:

let dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
println("App Path: \(dirPaths)")

Swift 3.0: let dirPaths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) print("App Path: \(dirPaths)")
u
user1039695

Use Finder-->go to folder and enter given basepath to reach application folders

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;

NSLog(@"%@",basePath);

O
Ohmy

The simulator puts the file in ~/Library/Developer/CoreSimulator/Devices/... but the path after /Devices is different for everyone.

Use this handy method. It returns the path of the temporary directory for the current user and takes no argument.

NSString * NSTemporaryDirectory ( void );

So in my ViewController class I usually put this line in my viewDidLoad just for a reference when I need to grab my CoreData stored file. Hope this helps.

  NSLog(@"FILE PATH :%@", NSTemporaryDirectory());

(Note: to go to the path, from the finder menu click on Go and type ~/Library to open hidden directory then in the Finder Window you can click on the path shown on your console.)


k
kakubei

This location has, once again, changed, if using Swift, use this to find out where the folder is (this is copied from the AppDelegate.swift file that Apple creates for you so if it doesn't work on your machine, search in that file for the right syntax, this works on mine using Xcode 6.1 and iOS 8 simulator):

let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
println("Possible sqlite file: \(urls)")

N
NSRover

The simulators are located under:

~/Library/Developer/CoreSimulator/

Here, they are listed as directories with UUID names. Use sort by 'Date modified' to find the latest one. Inside navigate to:

/data/Containers/Data/Application/

Here you will get a list of all the applications on that device. You can again sort this to get the latest app.

NOTE: Xcode changes the directory name every time you run the app, so don't rely on making alias/short cuts on desktop.

The easiest way is to use the app here, which does everything automatically.


A
Andrew

I created this script that will zip the latest app built for any simulator and zip it to the desktop.

https://gist.github.com/Gerst20051/8ca49d5afbf09007b3696fab6e9f425c

#!/bin/bash

DESTINATION_DIR="$HOME/Desktop"
APP_PATH=$(find ~/Library/Developer/CoreSimulator/Devices/*/data/Containers/Bundle/Application/*/*.app -type d -maxdepth 0 -print0 | xargs -0 ls -td | head -n1)
APP_DIRNAME=$(dirname "$APP_PATH")
APP_BASENAME=$(basename "$APP_PATH")
FILE_NAME="${APP_BASENAME%.*}"

cd "$APP_DIRNAME"
zip -qr "$DESTINATION_DIR/$FILE_NAME.zip" "$APP_BASENAME"

e
exp

In Swift 4 or Swift 5 you can use NSHomeDirectory().

The easiest way in Xcode 10 (or Xcode 11) is to pause your app (like when it hits a breakpoint) and run this line in the debugger console:

po NSHomeDirectory()

po stands for print object and prints most things


S
SpokaneDude
 1.   NSTemporaryDirectory() gives this:

    /Users/spokaneDude/Library/Developer/CoreSimulator/Devices/1EE69744-255A-45CD-88F1-63FEAD117B32/data/Containers/Data/Application/199B1ACA-A80B-44BD-8E5E-DDF3DCF0D8D9/tmp

 2. remove "/tmp" replacing it with "/Library/Application Support/<app name>/"  --> is where the .sqlite files reside

C
Community

With Swift 4, you can use the code below to get your app's home directory. Your app's document directory is in there. print(NSHomeDirectory()) I think you already know that your app's home directory is changeable, so if you don't want to add additional code to your codebase, SimPholder is a nice tool for you. And further more, you may wonder is there a tool, that can help you save time from closing and reopening same SQLite database every time after your app's home directory be changed. And the answer is yes, a tool I know is SQLiteFlow. From it's document, it says that: Handle database file name or directory changes. This makes SQLiteFlow can work friendly with your SQLite database in iOS simulator.


z
zapdroid

Here is the sh for last used simulator and application. Just run sh and copy printed text and paste and run command for show in finder.

#!/bin/zsh

lastUsedSimulatorAndApplication=`ls -td -- ~/Library/Developer/CoreSimulator/Devices/*/data/Containers/Data/Application/*/ | head -n1`

echo $lastUsedSimulatorAndApplication