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