Document directory path of Xcode Device Simulator

前端 未结 21 1430
旧巷少年郎
旧巷少年郎 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 03:03

    iOS 11

    if let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory,
                                                               .userDomainMask,
                                                               true).first {
        debugPrint("documentsPath = \(documentsPath)")
    }
    
    0 讨论(0)
  • 2020-11-28 03:04

    I faced the same issue when I stored the full path using CoreData. When retrieving the full path, it return null because the document folder UUID is different every time the app restarts. Following is my resolution:

    1. Make sure storing only the relative path of the document / file in CoreData. E.g. store "Files/image.jpg" instead of "/Users/yourname/.../Applications/UUID/Document/Files/image.jpg".
    2. Use the following to retrieve the app document location:

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

    3. Concatenate both #2 and #1 to get the full path of the document / file you want to retrieve.
    You can refer to Apple Developer Note: https://developer.apple.com/library/ios/technotes/tn2406/_index.html

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

    Based on Ankur's answer but for us Swift users:

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

    Put it inside ViewDidLoad and it will print out immediately upon execution of the app.

    0 讨论(0)
提交回复
热议问题