-->

UIDocumentPickerExtensionViewController validTypes

2019-09-05 04:51发布

问题:

Currently I'm creating a 'Document Provider Extension' for my iOS app. I'm using the extension from inside my app, as well as from other apps to get access to some app internal files.

When using it internally, I'm creating a 'UIDocumentPickerViewController' for example with the following code:

 UIDocumentPickerViewController*    documentPicker =
   [[UIDocumentPickerViewController alloc]
         initWithDocumentTypes:@[@"public.image"]
                        inMode:UIDocumentPickerModeImport];

The extension runs fine, with one exception: The 'validTypes' array is always 'nil', so I'm not able to limit the access to valid files only (in the example: image files).

I've also tested the extension with other apps (like Mail or Pixelmator): Same result; runs fine, but validTypes is always nil. Of course I do not know, how Mail or Pixelmator are initializing their document pickers.

Does anyone see my error? Or has anyone seen the same problem? And found a solution??

Many thanks!

回答1:

Maybe you're just checking the 'validTypes' array to early in the initialization process; I did so some time ago...

When walking through the initialization process of an UIDocumentPickerExtensionViewController step by step, you will see the following behavior:

- (void)viewDidLoad

    self.validTypes not set (==nil)

- (void)prepareForPresentationMode:(UIDocumentPickerMode)pMode

    self.validTypes is set (!= nil; maybe: @[@"com.adobe.pdf"])

- (void)viewWillLoad:(BOOL)animated

    self.validTypes is set (!= nil; maybe: @[@"com.adobe.pdf"])

- (void)viewDidLoad:

    self.validTypes is set (!= nil; maybe: @[@"com.adobe.pdf"])

Just try to check for valid types later :-)