Xcode: directory file for simulator Iphone

喜你入骨 提交于 2019-12-02 14:18:48

I'm not sure if you are able to write in your bundle, but you can in your Documents directory instead as your code does. Why don't you try this?

Use the same code and you will find your file in:

/Users/YOURUSER/Library/Application Support/iPhone Simulator/IOSVERSION/Applications/APPID/Documents/file.txt

This changed with XCode 6 and iOS 6 and this got tricky.

The documents directory are now hidden within:

~/Library/Developer/CoreSimulator/Devices/<some-id>/data/Containers/Data/Application/<some-other-id>

It seems the location is changing at each application start, so it's really hard to track. There is a simple tip I borrowed from this article and that I will include for the lazy ones:

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

Add this for example to your applicationDidFinishLaunching method, should make it easier!

If you want more details, just have a look to the original article

NB: I know the question is old, but well, I found it while searching, so I think adding an updated answer may serve some of us!

The Documents directory for your app in the simulator is located at;

~/Library/Application Support/iPhone Simulator/YOUR-IOS-VERSION/Applications/UNIQUE-KEY-FOR-YOUR-APP/Documents

Stop at a breakpoint anywhere in your app and type "po NSHomeDirectory()" in the debugger. Use Finder's Go > Go To Folder feature to jump directly there.

With the example code that you have here it will not write into your Resources folder, but into the Documents folder of the Simulator, which is actually where you should write on device, but as you mention that you only want to do this on the simulator, you could use

filePath = [[NSBundle mainBundle] bundlePath] stringByAppendingPathComnponent:@"Resources"]

But, don't do this in a shipping app, it will fail.

Paste this in the terminal.

open ~/Library/Application\ Support/iPhone\ Simulator/

In gdb, stop process and paste it, then the location of Documents will be printed. [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]

 po [[[NSFileManager defaultManager] URLsForDirectory:9 inDomains:1] lastObject]

If you are using Xcode 7 and higher follow this:

Documents Directory:

file:///Users/codercat/Library/Developer/CoreSimulator/Devices/YourProjectDict/data/Containers/Data/Application/(sample digit)7F53CFB3-C534-443F-B595-62619BA808F2/Documents/your file located here
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!