DetailsIPhone Simulator FileThe path is the content to be introduced in this article,Iphone/Ipod touch app development uses sandbox, which is something that programmers can accessFileIn the sandbox of your own program, the Directory of an application should be in addition to the compiled program.File, Usually there will be their own document, tmp directory, you can call the api to obtain these paths, and then save the file.
When xcode is used for compilation and execution, an iphone simulator is usually started to execute the app. However, the root directory of the generated app is different every time you start it with simulator.
This also means that if you have a copy of the data file, you need to put it in the document or tmp directory, and then read it in the application by calling APIs similar to GetDocumentDirectory, the results are all different paths. If you do not modify the code or re-compile the code, it will not. That is to say, each time you test and run, copy the data files you saved to the document in the program running Directory, which is very troublesome for debugging. How can this problem be solved?
It's actually quite simple... Just use the google method. Sandbox technology is a restriction when running real iphone/ipod touch. When running simulator, you can actually read files from other paths.
That is to say, you can put the file in another place you specified, instead of the document under the app, so that when you run the simulator, the app can also read files in a directory other than its sandbox. When an app is released, that is, running on the iphone/ipod touch, the root directory of each app is fixed and does not change dynamically when it runs the simulator ), put the data file in the real sandbox document or tmp directory.
To combine the above two cases, when running in the simulator mode, there will be
- TARGET_IPHONE_SIMULATOR
So we can write this when getting the file:
- - (NSString *) dataFilePath {
- #if TARGET_IPHONE_SIMULATOR
- return @"/Users/fengbo/project/test/yourFileName";
- #else
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory
- , NSUserDomainMask, YES);
- NSString *documentsDirectory = [paths objectAtIndex:0];
- return [documentsDirectory stringByAppendingPathComponent:@"yourFileName"];
- #endif
- }
In this way, the above two cases can be met.
Summary: DetailsIPhone Simulator FileThe content of the path has been introduced. I hope this article will help you!