I'm trying to use UIDocumentPickerViewController. It works fine on the simulator and also on a real device in debug mode.
I've tried replacing didPickDocumentAtURL with didPickDocumentsAtURLs but it still doesn't work. I've tried to output some statements inside the method but it doesn't appear as expected.
Here is the smallest code that can reproduce the issue. I have a main view with only one button and button tap handler is defined below.
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
[Toast show:[NSString stringWithFormat:@"select file's url is %@", [urls firstObject]]]; // not work
}
/* - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
} */
- (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller {
}
- (IBAction)buttonTapped:(id)sender {
UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"public.data"] inMode:UIDocumentPickerModeImport];
documentPicker.delegate = self;
[self presentViewController:documentPicker animated:YES completion:nil];
}
@end
When running on a real device in a real environment, an error will be output:
Tried to call delegate -documentBrowser:didPickDocumentURLs: with an empty array of items. This indicates the items failed to be prepared and materialized on disk: <private>