Reading a file from a hard drive in iPhone simulator

北慕城南 提交于 2021-02-07 06:46:46

问题


Is it possible to read a file (from my normal file system) into a iPhone App running on the iPhone Simulator?

I understand that the iPhone itself has not got a (user accessible) file system but this is simply for testing and will only ever be run in the simulator.

The file will be a text file that can be edited while the application is running, it will be read every-time a method is called.


回答1:


Yes, you can, and it doesn't matter where it is. Just give it an absolute path name when you load it (Xcode won't recognize a different working directory when running the simulator).




回答2:


Yes, you can if your file is within your app folder ~/Library/Application Support/iPhone Simulator/User/Applications/ [your app folder] /Documents




回答3:


No. Your app is running in its own sandbox on the phone. It's not allowed to read or write outside of it.

Edit: I think CiNN is correct. As long as your code stays on the simulator, you shouldn't have problems working with a file on your local drive.




回答4:


I personally think that the easiest way would be to enter "file:///" in Safari within the simulator, if thats what your looking for.




回答5:


It should also be noted that you can do this in reverse -- you can grab the files off your hard drive that your application created in the simulator. This is a good way to check out your results (data, images, whatever) without having to build a data "viewer" into the application.




回答6:


FYI 'newer' sds versions will do this... Search for iPad and you will find it. (for obvious reasons I cannot give more details here) good luck.



来源:https://stackoverflow.com/questions/811924/reading-a-file-from-a-hard-drive-in-iphone-simulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!