Commit 3146a3b6 authored by Pavel Akhrameev's avatar Pavel Akhrameev Committed by Carola Nitz

Multiple file selection from iCloud drive

parent 6b74f739
...@@ -22,13 +22,31 @@ ...@@ -22,13 +22,31 @@
#pragma mark - Internal Methods #pragma mark - Internal Methods
- (UIViewController *) configurePickerViewController {
NSArray *types = @[(id)kUTTypeAudiovisualContent];
UIDocumentPickerMode mode = UIDocumentPickerModeImport;
if (@available(iOS 11.2, *)) {
// UIDocumentMenuViewController deprecated and does not support multiple selection
UIDocumentPickerViewController *picker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes: types inMode:mode];
picker.delegate = self;
picker.allowsMultipleSelection = YES;
return picker;
} else {
UIDocumentMenuViewController *importMenu = [[UIDocumentMenuViewController alloc] initWithDocumentTypes:@[(id)kUTTypeAudiovisualContent] inMode:UIDocumentPickerModeImport];
importMenu.delegate = self;
return importMenu;
}
}
- (void)showDocumentMenuViewController:(id)sender - (void)showDocumentMenuViewController:(id)sender
{ {
UIDocumentMenuViewController *importMenu = [[UIDocumentMenuViewController alloc] initWithDocumentTypes:@[(id)kUTTypeAudiovisualContent] inMode:UIDocumentPickerModeImport]; UIViewController *picker = [self configurePickerViewController];
importMenu.delegate = self;
UIViewController *rootVC = [UIApplication sharedApplication].keyWindow.rootViewController; UIViewController *rootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
UIPopoverPresentationController *popoverPres = importMenu.popoverPresentationController; UIPopoverPresentationController *popoverPres = picker.popoverPresentationController;
if (popoverPres) { // not-nil on iPad if (popoverPres) { // not-nil on iPad
UIView *sourceView = nil; UIView *sourceView = nil;
...@@ -43,7 +61,7 @@ ...@@ -43,7 +61,7 @@
popoverPres.permittedArrowDirections = UIPopoverArrowDirectionLeft; popoverPres.permittedArrowDirections = UIPopoverArrowDirectionLeft;
} }
[rootVC presentViewController:importMenu animated:YES completion:nil]; [rootVC presentViewController:picker animated:YES completion:nil];
} }
#pragma mark - UIDocumentMenuDelegate #pragma mark - UIDocumentMenuDelegate
...@@ -57,6 +75,13 @@ ...@@ -57,6 +75,13 @@
#pragma mark - UIDocumentPickerDelegate #pragma mark - UIDocumentPickerDelegate
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray <NSURL *>*)urls NS_AVAILABLE_IOS(11_0);
{
for (NSURL *url in urls) {
[self documentPicker:controller didPickDocumentAtURL:url];
}
}
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url
{ {
NSFileManager *fileManager = [NSFileManager defaultManager]; NSFileManager *fileManager = [NSFileManager defaultManager];
...@@ -76,7 +101,6 @@ ...@@ -76,7 +101,6 @@
[alert addAction:okAction]; [alert addAction:okAction];
[rootVC presentViewController:alert animated:true completion:nil]; [rootVC presentViewController:alert animated:true completion:nil];
} }
} }
@end @end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment