I'm developing an app that provides the ability to store cloud documents.
This app will have the option to import data from other apps using the new UIDocumentPickerViewController
.
Everything works fine and I'm able to show the picker view controller.
This is the code that I'm using to import the file:
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
if (controller.documentPickerMode == UIDocumentPickerModeImport) {
dispatch_async(dispatch_get_main_queue(), ^{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString* path=[NSString stringWithFormat:@"%@/MyHandyTap/%@/%@",documentsDirectory,self.cartella,[url lastPathComponent]];
BOOL startAccessingWorked = [url startAccessingSecurityScopedResource];
NSURL *ubiquityURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
__block NSData *data;
NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] init];
NSError *error;
[fileCoordinator coordinateReadingItemAtURL:url options:0 error:&error byAccessor:^(NSURL *newURL) {
data = [NSData dataWithContentsOfURL:newURL];
[data writeToFile:path atomically:YES];
}];
[url stopAccessingSecurityScopedResource];
}
}
With this code I'm able to import a lot of different file formats (.pdf, .txt, .rtf, .doc etc) however if I try to import files .pages or .numbers files from iCloud the call to [NSData dataWithContentsOfURL:newURL]
returns null
.
Is it possibile to let users import these kinds of files?
I've red the documentation listed here https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/ExtensibilityPG/FileProvider.html#//apple_ref/doc/uid/TP40014214-CH18-SW2 and I've downloaded the example listed here : https://developer.apple.com/devcenter/download.action?path=/wwdc_2014/wwdc_2014_sample_code/newboxanintroductiontoiclouddocumentenhancementsinios8.0.zip however I'm not able to figure out how to solve this issue.
Thank you in advance for your help
Andrea
Even I did not test it, but likely you get the problems, because documents of type .pages or .numbers are no single files, but bundles. So you cannot read them with -dataWithContentsOfURL:
.
Did you check copying with -copyItemAtURL:toURL:error:
(NSFileManager
)?