2015-04-01 160 views

回答

0

你只能在你的應用程序的沙箱中查看文件。每個應用程序都有一個文件,緩存和臨時文件夾。

示例代碼:

NSError *err  = nil; 
NSArray *myPathList = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 
NSString *myPath = [myPathList objectAtIndex:0]; 
NSArray *dirContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:myPath error:&err]; 
if(err) NSLog(@"ERROR: %@",[err localizedDescription]); 
NSMutableArray *filePaths = nil; 

int count = (int)[dirContent count]; 
for(int i=0; i<count; i++) 
{ 
    [filePaths addObject:[dirContent objectAtIndex:i]]; 
} 
return filePaths; 
+0

非常感謝您的回覆。我想瀏覽PDF文件並允許用戶選擇並上傳。我已經實現了圖像,但我沒有找到PDf文件的任何解決方案。 – 2015-04-01 06:57:55

+0

正如我所提到的,您只能訪問您應用的沙盒中的文件。沒有辦法像您從iPhone圖庫中的圖像那樣列出pdf。 – Ajumal 2015-04-01 10:05:51