Document directory path of Xcode Device Simulator

前端 未结 21 1431
旧巷少年郎
旧巷少年郎 2020-11-28 02:28

In iOS 7, the document directory of the iOS simulators can be found in:

/Users/Sabo/Library/Application Support/iPhone Simulator/

However,

相关标签:
21条回答
  • 2020-11-28 02:51

    Try ~/Library/Developer/CoreSimulator/Devices/

    0 讨论(0)
  • 2020-11-28 02:52

    in Appdelegate, put this code to see Document and Cache Dir:

    #if TARGET_IPHONE_SIMULATOR
        NSLog(@"Documents Directory: %@", [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]);
        NSArray* cachePathArray = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
        NSString* cachePath = [cachePathArray lastObject];
        NSLog(@"Cache Directory: %@", cachePath);
    #endif
    

    on Log:

    Documents Directory: /Users/xxx/Library/Developer/CoreSimulator/Devices/F90BBF76-C3F8-4040-9C1E-448FAE38FA5E/data/Containers/Data/Application/3F3F6E12-EDD4-4C46-BFC3-58EB64D4BCCB/Documents/

    Cache Directory: /Users/xxx/Library/Developer/CoreSimulator/Devices/F90BBF76-C3F8-4040-9C1E-448FAE38FA5E/data/Containers/Data/Application/3F3F6E12-EDD4-4C46-BFC3-58EB64D4BCCB/Library/Caches

    0 讨论(0)
  • 2020-11-28 02:57

    It is correct that we need to look into the path ~/Library/Developer/CoreSimulator/Devices/.

    But the issue I am seeing is that the path keeps changing every time I run the app. The path contains another set of long IDs after the Application string and that keeps changing every time I run the app. This basically means that my app will not have any cached data when it runs the next time.

    0 讨论(0)
  • 2020-11-28 02:58

    Just write bellow code in AppDelegate -> didFinishLaunchingWithOptions
    Objective C

    #if TARGET_IPHONE_SIMULATOR 
    // where are you? 
    NSLog(@"Documents Directory: %@", [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]); 
    #endif 
    


    Swift 2.X

    if let documentsPath = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first?.path {
        print("Documents Directory: " + documentsPath)   
    }
    

    Swift 3.X

    #if arch(i386) || arch(x86_64)
        if let documentsPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.path {
            print("Documents Directory: \(documentsPath)")
        }
    #endif
    

    Swift 4.2

    #if targetEnvironment(simulator)
        if let documentsPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.path {
            print("Documents Directory: \(documentsPath)")
        }
    #endif
    

    Output
    /Users/mitul_marsonia/Library/Developer/CoreSimulator/Devices/E701C1E9-FCED-4428-A36F-17B32D32918A/data/Containers/Data/Application/25174F64-7130-4B91-BC41-AC74257CCC6E/Documents

    Copy your path from "/Users/mitul_marsonia/Library/Developer/CoreSimulator/Devices/E701C1E9-FCED-4428-A36F-17B32D32918A..." go to "Finder" and then "Go to Folder" or command + shift + g and paste your path, let the mac take you to your documents directory

    0 讨论(0)
  • 2020-11-28 02:59

    If your app uses CoreData, a nifty trick is to search for the name of the sqlite file using terminal.

    find ~ -name my_app_db_name.sqlite
    

    The results will list the full file paths to any simulators that have run your app.

    I really wish Apple would just add a button to the iOS Simulator file menu like "Reveal Documents folder in Finder".

    0 讨论(0)
  • 2020-11-28 03:01

    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
    
    0 讨论(0)
提交回复
热议问题