5

I am developing my storage provider and use Apple’s “NewBox”(it's link was expired) sample code as the host app. Ideally I hope to see I can import(copy) files from the storage provider to my NewBox's sandbox or export/move file to other apps.

At NewBox host app, when I want to import file, I use:

UIDocumentMenuViewController *vc = [[UIDocumentMenuViewController alloc] initWithDocumentTypes:@[(NSString *)kUTTypeRTF,(NSString *)kUTTypePNG,(NSString *)kUTTypeText,(NSString *)kUTTypePlainText,(NSString *)kUTTypePDF, (NSString *)kUTTypeImage] inMode:UIDocumentPickerModeImport];



Once I pick up a file, in my UIDocumentPickerExtensionViewController, I invoke :

- (void)pickDocument:(NSURL *)documentURL {
    [self dismissGrantingAccessToURL:documentURL];
}


After invoking dismissGrantingAccessToURL, the picker’s view will dismissed and return back to host app, and host app’s didPickDocumentAtURL will be invoked.

However, "didPickDocumentAtURL" receive the URL of the original file I selected, not the new URL that system copies to NewBox’s sandbox. This is also familiar to circumstances of export and move. Do I misunderstand the import/export/move? I thought this action about files such as copying to host app’s sandbox is done by system, and the host app will get a new URL of the file to access.

I've tried on iOS8 beta4, and this problem still exists.

Thanks!

  • Hey..Does this method "didPickDocumentAtURL" work for you?..After I pick docs from iCloud ,control doesn't even come to this method..what am I missing here? – Shikha Shah Oct 10 '14 at 19:59
  • You mean didPickDocumentAtURL of host app? It might be a bug that sometimes it didn't called. I will manually close the app and try it again with it being correctly called. – user3793349 Oct 17 '14 at 12:23

1 Answers1

3

The URL you get from documentPicker:didPickDocumentAtURL: depends on the operation:

  • Import/Export:/data/Containers/Data/Application/$(AppIDOfAppPresentingUIDocumentPickerViewController)/tmp/DocumentPickerIncoming/File.txt

  • Open/Move: /data/Containers/Shared/AppGroup/$(ExtensionAppGroupID)/File%20Provider%20Storage/File.txt

Where "File.txt" can be any file name or file path.

In case of an import, the app presenting the picker is responsible for moving the file at the given URL to a permanent location. In case of an open or move, the app should probably save the URL for future use (always use it in a a file coordinator). In case of an export, the URL is typically ignored.

The NewBox project can be downloaded from Apple's web site https://developer.apple.com/devcenter/download.action?path=/wwdc_2014/wwdc_2014_sample_code/newboxanintroductiontoiclouddocumentenhancementsinios8.0.zip

davidisdk
  • 3,358
  • 23
  • 12