[super viewDidLoad]; // 获取App的Sandbox路径 NSString *sandboxPath = NSHomeDirectory(); NSLog(@"%@",sandboxPath); //获取Documents路径 NSString *doc = [sandboxPath stringByAppendingPathComponent:@"Documents"]; NSLog(@"doc:%@",doc); //另一种获取Documents路径的方式 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *doc1 = [paths firstObject]; NSLog(@"Doc:%@",doc1); //获取Library的路径 NSString *lib = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject]; NSLog(@"%@",lib); //获取Library下的Caches目录 NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)firstObject]; NSLog(@"Caches:%@",caches); //获取临时目录下tmp NSString *tmp = NSTemporaryDirectory(); NSLog(@"tmp:%@",tmp); //如何获取应用程序本身的路径 NSBundle *mainBundle = [NSBundle mainBundle];//mainBundle 对象代表应用程序本身的内容 NSString *path = [mainBundle pathForResource:@"a" ofType:@"jpg"]; NSLog(@"%@",path); //获取Url NSURL *url = [mainBundle URLForResource:@"a" withExtension:@"jpg"]; NSLog(@"url:%@",url);
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/3355.html