Obtain the path for iOS

Source: Internet
Author: User

Because of various requirements, the paths to be obtained are inconsistent, so write this article for memo.

- (NSString *)getDocumentPath{    NSString *path = nil;        // Method 1    NSArray *pathsArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);    path = [pathsArray objectAtIndex:0];        // Method 2//    path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];        return path;}- (NSString *)getAppPath{    NSString *path = nil;        path = NSHomeDirectory();        return path;}
// In the tmp directory, we can write data that is needed when the program is running. The data written in the tmp directory will not exist after the program exits. -(Nsstring *) gettmppath {nsstring * Path = nil; Path = nstemporarydirectory (); return path;}-(nsstring *) getapppackagepath {nsstring * Path = nil; // method 1 Path = [[nsbundle mainbundle] resourcepath]; // method 2 return path;}-(nsstring *) getfilepath {nsstring * Path = nil; nsfilemanager * filemanager = [nsfilemanager defaultmanager]; nsurl * pathurl = [filemanager urlfordirectory: nsapplicationsuppdirectory directory indomain: nsuserdomainmask metadata: Nil create: Yes error: NULL]; Path = [pathurl path]; return Path ;}

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.