Detailed description of the iPhone Simulator file path

Source: Internet
Author: User

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

 
 
  1. TARGET_IPHONE_SIMULATOR 

So we can write this when getting the file:

 
 
  1. - (NSString *) dataFilePath {  
  2. #if TARGET_IPHONE_SIMULATOR  
  3.  return @"/Users/fengbo/project/test/yourFileName";  
  4. #else  
  5.  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory  
  6.   , NSUserDomainMask, YES);  
  7.  NSString *documentsDirectory = [paths objectAtIndex:0];  
  8.  return [documentsDirectory stringByAppendingPathComponent:@"yourFileName"];  
  9. #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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.