Sunday, 13 March 2011

Documents Directory File Path - iPhone, iPad, iOS Development

Getting the file path to the documents directory is very simple however the documentation in this area can be rather confusing.

Firstly you call the function NSSearchPathForDirectoriesInDomains(). This function returns an array however there will almost always only be one object within the array.

 NSArray * NSSearchPathForDirectoriesInDomains (  NSSearchPathDirectory directory,  NSSearchPathDomainMask domainMask,  BOOL expandTilde );

The reference for the method is shown above.
The Directory value must be one of the predefined search path directories of the operating system. The most commonly used directory and the one we'll use here is the documents directory which the value for is NSDocumentDirectory.  
Other values can be seen in the documentation here.
The domain mask value is most often NSUserDomainMask meaning the returned path is local to the user's home directory.  Other possible values are shown below.
 NSUserDomainMask - Local to the user's home directory.
 NSLocalDomainMask - local to the current machine.
 NSNetworkDomainMask - Publicly available location in the local area network.
 NSSystemDomainMask - /System (Usually unused private).
 NSAllDomainsMask - will return a path for each of the above domains.
The full example of how to obtain a string of the system file path to the user documents directory is shown below.
 -(NSString *)documentsDirectoryPath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
return documentsDirectoryPath;
}

9 comments:

  1. Hello,
    The first thing you should do when looking to hire a freelance iPhone developer is to outline what type of development you need done for the iPhone.
    hire iphone Developer

    ReplyDelete
  2. I posted a question on StackOverflow about NSSearchPathForDirectoriesInDomains - it's returning the wrong directory. Do you know why this would be happening? http://stackoverflow.com/questions/6515979/nssearchpathfordirectoriesindomains-returns-the-wrong-directory

    ReplyDelete
  3. I have read this post. collection of post is a nice one ..that am doing website designing company chennai india and website development company chennai india. That I will inform about your post to my friends and all the best for your future posts..

    ReplyDelete
  4. Now day's demand of iPhone application is increasing very fast. This is the appropriate blog for any iPhone developer who wants to outsource their iPhone application development.

    ReplyDelete
  5. Thanks For Sharing This Post

    For More Information You Can Visit This Website iPhone Application Development Solutions

    ReplyDelete
  6. Nice Post ..!! I really i like the way of your writing this post. You have shared a very interesting and informative post about Mobile platform .. keep Updating..!!
    Android Application Development

    ReplyDelete
  7. If you are searching for cost effective as well as solid Mobile Application Development Services and Web Development in India provider then without thinking much you can choose to hire the services offered by Acetech. We are one of the leading companies offering affordable, timely and quality mobile apps services.

    ReplyDelete
  8. Today all users crazy about new iphone apps and iPhone become more necessary for people even businesspersons. If you want to development customs, iphone application development then must hire a well-reputed development company.

    ReplyDelete