① ios怎樣取得沙盒中的具體的文件
在製作應用的時候經常用到沙盒路徑 存取文件
路徑的說明
Documents:應用中用戶數據可以放在這里,iTunes備份和恢復的時候會包括此目錄
tmp:存放臨時文件,iTunes不會備份和恢復此目錄,此目錄下文件可能會在應用退出後刪除
Library/Caches:存放緩存文件,iTunes不會備份此目錄,此目錄下文件不會在應用退出刪除
用代碼來獲取Documents用戶數據路徑
[(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
用代碼來獲取Library/Caches緩存目錄(配置文件以及用戶緩存存放位置)
(NSLibraryDirectory, NSUserDomainMask, YES);
用代碼獲取tmp臨時目錄
[NSHomeDirectory() stringByAppendingFormat:@"/tmp"];//在系統主目錄下查找tmp文件夾
② iOS怎麼獲取並移除沙盒中Documents文件夾下的所有文件
1、將所有文件存入數組
NSString*string=[(NSDocumentDirectory,NSUserDomainMask,YES)objectAtIndex:0];
NSFileManager*fileManager=[NSFileManagerdefaultManager];
NSArray*tempFileList=[[NSArrayalloc]initWithArray:[:stringerror:nil]];
2、移除所有文件
NSString*DocumentsPath=[NSHomeDirectory():@"Documents"];
NSDirectoryEnumerator*enumerator=[[NSFileManagerdefaultManager]enumeratorAtPath:DocumentsPath];
for(NSString*fileNameinenumerator){
[[NSFileManagerdefaultManager]removeItemAtPath:[DocumentsPath:fileName]error:nil];
}
3、移除所有png文件
NSString*extension=@"png";
NSFileManager*fileManager=[NSFileManagerdefaultManager];
NSArray*paths=(NSDocumentDirectory,NSUserDomainMask,YES);
NSString*documentsDirectory=[pathsobjectAtIndex:0];
NSArray*contents=[:documentsDirectoryerror:nil];
NSEnumerator*enumerator=[contentsobjectEnumerator];
NSString*filename;
while((filename=[enumeratornextObject])){
if([[filenamepathExtension]isEqualToString:extension]){
[fileManagerremoveItemAtPath:[documentsDirectory:filename]error:nil];
}
}
③ 蘋果手機怎麼能找到軟體下載的文件夾文件
1、首先要看一下蘋果手機下載的文件是屬於什麼類型,如果是txt、word等形式的可以在原來的下載記錄中找到並打開,由於蘋果手機的局限性,下載的東西並不能找到存放目錄或是下載目錄的。
2、如果手機下載的是視頻文件,該視頻文件一般是通過蘋果手機播放軟體中下載的,下載的視頻文件也一般是在該播放軟體中找得到,比如蘋果手機通過優酷下載的視頻文件可以在優ap的緩存等處找到。
④ 為什麼ios中的沙盒路徑找不到文件
1、模擬器沙盒目錄
文件都在個人用戶名文件夾下的一個隱藏文件夾里,中文叫資源庫,他的目錄其實是Library。
因為應用是在沙箱(sandbox)中的,在文件讀寫許可權上受到限制,只能在幾個目錄下讀寫文件:
Documents:應用中用戶數據可以放在這里,iTunes備份和恢復的時候會包括此目錄
tmp:存放臨時文件,iTunes不會備份和恢復此目錄,此目錄下文件可能會在應用退出後刪除
Library/Caches:存放緩存文件,iTunes不會備份此目錄,此目錄下文件不會在應用退出刪除
iTunes在與iPhone同步時,備份所有的Documents和Library文件。
iPhone在重啟時,會丟棄所有的tmp文件。
查看方法:
方法1、可以設置顯示隱藏文件,然後在Finder下直接打開。設置查看隱藏文件的方法如下:打開終端,輸入命名
(1)顯示Mac隱藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool true
(2)隱藏Mac隱藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool false
(3)輸完單擊Enter鍵,退出終端,重新啟動Finder就可以了 重啟Finder:滑鼠單擊窗口左上角的蘋果標志-->強制退出-->Finder-->
現在能看到資源庫文件夾了。
打開資源庫後找到/Application Support/iPhone Simulator/文件夾。這裡面就是模擬器的各個程序的沙盒目錄了。
方法2、這種方法更方便,在Finder上點->前往->前往文件夾,輸入/Users/username/Library/Application Support/iPhone Simulator/ 前往。
username這里寫用戶名。
代碼查看目錄:
NSString *path = NSHomeDirectory();//主目錄
NSLog(@"NSHomeDirectory:%@",path);
NSString *userName = NSUserName();//與上面相同
NSString *rootPath = NSHomeDirectoryForUser(userName);
NSLog(@"NSHomeDirectoryForUser:%@",rootPath);
NSArray *paths = (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory=[paths objectAtIndex:0];//Documents目錄
NSLog(@"NSDocumentDirectory:%@",documentsDirectory);
結果如下:
2013-09-03 20:31:27.210 ios那啥[8383:c07] NSHomeDirectory:/Users/wmm/Library/Application Support/iPhone Simulator/6.1/Applications/D803DBD2-9CB2-4D18-9152-6E9398EFF5DB2013-09-03 20:31:27.210 ios那啥[8383:c07] NSHomeDirectoryForUser:/Users/wmm/Library/Application Support/iPhone Simulator/6.1/Applications/D803DBD2-9CB2-4D18-9152-6E9398EFF5DB2013-09-03 20:31:27.211 ios那啥[8383:c07] NSDocumentDirectory:/Users/wmm/Library/Application Support/iPhone Simulator/6.1/Applications/D803DBD2-9CB2-4D18-9152-6E9398EFF5DB/Documents 自定義類返回各目錄路徑:
#import <Foundation/Foundation.h>
@interface ICSandboxHelper : NSObject
+ (NSString *)homePath; // 程序主目錄,可見子目錄(3個):Documents、Library、tmp
+ (NSString *)appPath; // 程序目錄,不能存任何東西
+ (NSString *)docPath; // 文檔目錄,需要ITUNES同步備份的數據存這里,可存放用戶數據
+ (NSString *)libPrefPath; // 配置目錄,配置文件存這里
+ (NSString *)libCachePath; // 緩存目錄,系統永遠不會刪除這里的文件,ITUNES會刪除
+ (NSString *)tmpPath; // 臨時緩存目錄,APP退出後,系統可能會刪除這里的內容
+ (BOOL)hasLive:(NSString *)path; //判斷目錄是否存在,不存在則創建
#import "ICSandboxHelper.h"
@implementation ICSandboxHelper
+ (NSString *)homePath{
return NSHomeDirectory();
}
+ (NSString *)appPath
{
NSArray * paths = (NSApplicationDirectory, NSUserDomainMask, YES);
return [paths objectAtIndex:0];
}
+ (NSString *)docPath
{
NSArray * paths = (NSDocumentDirectory, NSUserDomainMask, YES);
return [paths objectAtIndex:0];
}
+ (NSString *)libPrefPath
{
NSArray * paths = (NSLibraryDirectory, NSUserDomainMask, YES);
return [[paths objectAtIndex:0] stringByAppendingFormat:@"/Preference"];
}
+ (NSString *)libCachePath
{
NSArray * paths = (NSLibraryDirectory, NSUserDomainMask, YES);
return [[paths objectAtIndex:0] stringByAppendingFormat:@"/Caches"];
}
+ (NSString *)tmpPath
{return [NSHomeDirectory() stringByAppendingFormat:@"/tmp"];
}
+ (BOOL)hasLive:(NSString *)path
{
if ( NO == [[NSFileManager defaultManager] fileExistsAtPath:path] )
{
return [[NSFileManager defaultManager] createDirectoryAtPath:path
withIntermediateDirectories:YES
attributes:nil
error:NULL];
}
return NO;
}
⑤ ios 開發怎麼獲取沙盒目錄document下的文件夾個數
如何查看、管理ios模擬器上的文件? ios模擬器的路徑-打開沙盒路徑 1、模擬器沙盒目錄 文件都在個人用戶名文件夾下的一個隱藏文件夾里,中文叫資源庫,他的目錄其實是Library。 1.1 方法1、可以設置顯示隱藏文件,然後在Finder下直接打開。