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;
}

27 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
  9. Great article ...Thanks for your great information, the contents are quiet interesting. I will be waiting for your next post.
    iphone app development usa

    ReplyDelete
  10. I am glad after reading your technical blog... Your blog is excellent & you are helping others by posting these type of articles publicly... Appreciated
    biggest iphone apps development company

    ReplyDelete
  11. Thanks for giving knowledge Excellent overview :)
    android developer USA

    ReplyDelete
  12. Thanks so much for such a useful collection. And i must tell you guys , it is worth visiting our page for more relevant information and iphone apps development works and services.. http://www.siliconithub.com/mobile-apps-developer/iphone-application-development.html

    ReplyDelete

  13. Really nice information you had posted. Its very informative and definitely it will be useful for many people
    iOS Training in Chennai
    Android Training in Chennai
    php Training in Chennai

    ReplyDelete
  14. Being new to the blogging world I feel like there is still so much to learn. Your tips helped to clarify a few things for me as well as giving..

    Mobile App Development Company in Chennai
    Android app Development Company in Chennai
    ios app development Company in Chennai

    ReplyDelete
  15. "Beautiful Blog. Great content."!!
    "Really nice and awesome "!!


    mobile app development for android

    ReplyDelete
  16. It's interesting that many of the bloggers your tips helped to clarify a few things for me as well as giving.. very specific nice content. And tell people specific ways to live their lives.Sometimes you just have to yell at people and give them a good shake to get your point across.
    Mobile App Development Company
    Android app Development Company
    ios app development Company
    Mobile App Development Companies

    ReplyDelete
  17. We are also providing best mobile solutions, web design and development, ecommerce solution, SEO.
    Check out us here
    Web Design company in Hubli | web designing in Hubli | SEO company in Hubli

    ReplyDelete
  18. You have provided an nice article, Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things...

    Mobile App Development Company
    Mobile App Development Company
    Mobile app Development Companies

    ReplyDelete
  19. Thank you for taking the time to publish this information very useful!
    sell used cellphones

    ReplyDelete
  20. These ways are very simple and very much useful, as a beginner level these helped me a lot thanks fore sharing these kinds of useful and knowledgeable information.
    Android App Development Company

    ReplyDelete
  21. great and nice blog thanks sharing..I just want to say that all the information you have given here is awesome...Thank you very much for this one.
    web design Company
    web development Company
    web design Company in chennai
    web development Company in chennai
    web design Company in India
    web development Company in India

    ReplyDelete
  22. it is really amazing...thanks for sharing....provide more useful information...
    Mobile app development company

    ReplyDelete
  23. I wondered upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.

    Fitness SMS
    Salon SMS
    Investor Relation SMS

    ReplyDelete
  24. This article is very much helpful and i hope this will be an useful information for the needed one. Keep on updating these kinds of informative things...

    iOS App Development Company

    ReplyDelete
  25. great and nice blog thanks sharing..I just want to say that all the information you have given here is awesome...Thank you very much for this one.
    web design Company
    web development Company
    web design Company in chennai
    web development Company in chennai
    web design Company in India
    web development Company in India

    ReplyDelete