iOS獲取App各種文件的路徑方法匯集
[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);</pre>
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!