iOS提供沙盒機制,保證我們所有運行的應用都是在一個沙盒模塊里面。沙盒會有這么幾個特點:
每個應用程序都有自己的存儲空間;
應用程序不能直接去訪問別的程序的存儲內容。比如說它不能讀取其他app文件或者內容;
應用程序所請求的數據都要通過權限的檢測。這里所說的請求數據,就是類似于短信,照片等等這些數據,如果我們應用程序要去訪問這些數據,那么他會通過一個權限檢測,讓用戶決定是否允許你去訪問這個數據。
獲取沙盒的路徑:
獲取沙盒根目錄:
NSString *homeDirectory = NSHomeDirectory();
NSLog(@”homeDirectory:%@”, homeDirectory);
獲取document目錄
NSArray *documentPaths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [documentPaths objectAtIndex:0];
NSLog(@”documentPath:%@”, documentPath);
獲取Library目錄
NSArray *libraryPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *libraryPath = [libraryPaths objectAtIndex:0];
NSLog(@”libraryPath:%@”, libraryPath);
獲取Cache目錄
NSArray *cachePaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachePath = [cachePaths objectAtIndex:0];
NSLog(@”cachePath:%@”, cachePath);
獲取Tmp目錄
NSString *tmpPath = NSTemporaryDirectory();
NSLog(@”tmpPath:%@”, tmpPath);
bundle路徑
NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
NSLog(@”%@”,bundlePath);
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@”test” ofType:@”png”];
NSLog(@”%@”,imagePath);
回答所涉及的環境:聯想天逸510S、Windows 10。
iOS提供沙盒機制,保證我們所有運行的應用都是在一個沙盒模塊里面。沙盒會有這么幾個特點:
每個應用程序都有自己的存儲空間;
應用程序不能直接去訪問別的程序的存儲內容。比如說它不能讀取其他app文件或者內容;
應用程序所請求的數據都要通過權限的檢測。這里所說的請求數據,就是類似于短信,照片等等這些數據,如果我們應用程序要去訪問這些數據,那么他會通過一個權限檢測,讓用戶決定是否允許你去訪問這個數據。
獲取沙盒的路徑:
獲取沙盒根目錄:
NSString *homeDirectory = NSHomeDirectory();
NSLog(@”homeDirectory:%@”, homeDirectory);
獲取document目錄
NSArray *documentPaths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [documentPaths objectAtIndex:0];
NSLog(@”documentPath:%@”, documentPath);
獲取Library目錄
NSArray *libraryPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *libraryPath = [libraryPaths objectAtIndex:0];
NSLog(@”libraryPath:%@”, libraryPath);
獲取Cache目錄
NSArray *cachePaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachePath = [cachePaths objectAtIndex:0];
NSLog(@”cachePath:%@”, cachePath);
獲取Tmp目錄
NSString *tmpPath = NSTemporaryDirectory();
NSLog(@”tmpPath:%@”, tmpPath);
bundle路徑
NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
NSLog(@”%@”,bundlePath);
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@”test” ofType:@”png”];
NSLog(@”%@”,imagePath);
回答所涉及的環境:聯想天逸510S、Windows 10。