简体   繁体   English

iOS档案浏览应用程式

[英]iOS File Browsing app

I am attempting to create a file browsing app for iPads. 我正在尝试为iPad创建一个文件浏览应用程序。 I'm reluctant to use another app, such as Documents5, because I want to custom design it and bring in features we need. 我不愿意使用其他应用程序,例如Documents5,因为我想对其进行定制设计并引入我们需要的功能。

Essentially I am looking to create an almost identical app to Documents5 with iCloud Drive support. 本质上,我希望创建一个与iCloud Drive支持几乎相同的应用程序与Documents5。

I have the code for viewing PDFs, MP3s etc., but I'm a bit bewildered with iCloud Drive integration and the menu interface for file browsing. 我拥有用于​​查看PDF,MP3等的代码,但是iCloud Drive集成和用于文件浏览的菜单界面让我有些困惑。 Additionally, although I already have code for this, how do I link the files to the viewer/player? 此外,尽管我已经有代码,但是如何将文件链接到查看器/播放器?

iCloud Drive is pretty easy to implement. iCloud Drive非常易于实施。 Assuming that your app has all entitlements and so on properly set up, you can move files to and delete files from iCloud by interacting with it like it is any other directory. 假设您的应用具有所有权利,并已进行了正确的设置,则可以像与其他目录一样通过与iCloud进行交互来将文件移至iCloud或从iCloud删除文件。 You access the directory like this 您可以像这样访问目录

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

Moving files to this directory (to iCloud) is done like this 像这样将文件移动到该目录(到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];


The easiest way to display files is through a table view. 显示文件的最简单方法是通过表格视图。 You can implement a system where the file paths are stored in an array, so that when a cell is selected, you can decide how to open it based off of the file's extension. 您可以实现一个将文件路径存储在数组中的系统,以便在选择单元格时,可以根据文件扩展名决定如何打开它。 For example, let's say your table view looks like this 例如,假设您的表格视图如下所示

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

if your user selects row 1 ( text.txt ), you could implement something like this 如果您的用户选择第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