Reputation: 1
I am attempting to create a file browsing app for iPads. I'm reluctant to use another app, such as Documents5, because I want to custom design it and bring in features we need.
Essentially I am looking to create an almost identical app to Documents5 with iCloud Drive support.
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. Additionally, although I already have code for this, how do I link the files to the viewer/player?
Upvotes: 0
Views: 90
Reputation: 5745
iCloud Drive is pretty easy to implement. 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. 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
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 |
if your user selects row 1 (text.txt
), you could implement something like this
- (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
}
}
Upvotes: 1