簡體   English   中英

iOS檔案瀏覽應用程式

[英]iOS File Browsing app

我正在嘗試為iPad創建一個文件瀏覽應用程序。 我不願意使用其他應用程序,例如Documents5,因為我想對其進行定制設計並引入我們需要的功能。

本質上,我希望創建一個與iCloud Drive支持幾乎相同的應用程序與Documents5。

我擁有用於​​查看PDF,MP3等的代碼,但是iCloud Drive集成和用於文件瀏覽的菜單界面讓我有些困惑。 此外,盡管我已經有代碼,但是如何將文件鏈接到查看器/播放器?

iCloud Drive非常易於實施。 假設您的應用具有所有權利,並已進行了正確的設置,則可以像與其他目錄一樣通過與iCloud進行交互來將文件移至iCloud或從iCloud刪除文件。 您可以像這樣訪問目錄

- (NSString *)iCloudPath
{
    NSURL *URL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
    return [[URL path] stringByAppendingPathComponent:@"Documents"];
}

像這樣將文件移動到該目錄(到iCloud)

NSString *fileName = //the name of the file;
NSURL *fileURL = //the file you want to move;    
NSString *iCloudPath = [self iCloudPath];
[[NSFileManager defaultManager] setUbiquitous:YES itemAtURL:fileURL destinationURL:[NSURL fileURLWithPath:[iCloudPath stringByAppendingPathComponent:fileName]] error:nil];


顯示文件的最簡單方法是通過表格視圖。 您可以實現一個將文件路徑存儲在數組中的系統,以便在選擇單元格時,可以根據文件擴展名決定如何打開它。 例如,假設您的表格視圖如下所示

 ----------------- | video.mp4 | ----------------- | text.txt | ----------------- | file.pdf | 

如果您的用戶選擇第1行( text.txt ),則可以實現類似

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSString *filePath = self.files[indexPath.row]; NSString *fileExtension = [filePath pathExtension]; if ([fileExtension isEqualToString:@"txt"]) { //open the text file } } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM