[英]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.