-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[file_selector] Basic iOS implementation #5448
Changes from 1 commit
6e7f572
b4e8697
75a1bdc
15f2741
62c60cb
696cb78
11504f4
252e110
cb76a80
ecfad9a
4ecda0e
2a69911
38742a3
ec291b6
f0bbcf1
edc2881
e521edc
eabcce5
d39d953
170c260
129a097
0cfa61c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,19 +3,9 @@ | |
| // found in the LICENSE file. | ||
|
|
||
| #import "FLTFileSelectorPlugin.h" | ||
| #import "FLTFileSelectorPlugin_Test.h" | ||
| #import "messages.g.h" | ||
|
|
||
| @interface FLTFileSelectorPlugin () <UIDocumentPickerDelegate, FLTFileSelectorApi> | ||
|
|
||
| /** | ||
| * The completion block of a FLTFileSelectorApi request. | ||
| * It is saved and invoked later in a UIDocumentPickerDelegate method. | ||
| */ | ||
| @property(nonatomic) void (^pendingCompletion)(NSArray<NSString *> * _Nullable, | ||
| FlutterError * _Nullable); | ||
|
|
||
| @end | ||
|
|
||
| @implementation FLTFileSelectorPlugin | ||
|
|
||
| #pragma mark - FLTFileSelectorApi | ||
|
|
@@ -30,17 +20,18 @@ - (void)openFileSelectorWithConfig:(FLTFileSelectorConfig *)config | |
| return; | ||
| } | ||
|
|
||
| UIDocumentPickerViewController *documentPicker = | ||
| UIDocumentPickerViewController *documentPicker = self.documentPickerViewControllerOverride ?: | ||
| [[UIDocumentPickerViewController alloc] initWithDocumentTypes:config.utis | ||
|
||
| inMode:UIDocumentPickerModeImport]; | ||
| documentPicker.delegate = self; | ||
| if (@available(iOS 11.0, *)) { | ||
| documentPicker.allowsMultipleSelection = config.allowMultiSelection.boolValue; | ||
| } | ||
|
|
||
| UIViewController *rootVC = UIApplication.sharedApplication.delegate.window.rootViewController; | ||
| if (rootVC) { | ||
| [rootVC presentViewController:documentPicker animated:YES completion:nil]; | ||
| UIViewController *presentingVC = self.presentingViewControllerOverride ?: | ||
| UIApplication.sharedApplication.delegate.window.rootViewController; | ||
| if (presentingVC) { | ||
| [presentingVC presentViewController:documentPicker animated:YES completion:nil]; | ||
| self.pendingCompletion = completion; | ||
|
||
| } else { | ||
| completion(nil, [FlutterError errorWithCode:@"error" | ||
|
|
@@ -60,6 +51,7 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar { | |
|
|
||
| - (void)documentPicker:(UIDocumentPickerViewController *)controller | ||
| didPickDocumentAtURL:(NSURL *)url { | ||
| // This method is only called in iOS < 11.0. | ||
| if (self.pendingCompletion) { | ||
| self.pendingCompletion(@[ url.path ], nil); | ||
| self.pendingCompletion = nil; | ||
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #import "FLTFileSelectorPlugin.h" | ||
|
|
||
| #import "messages.g.h" | ||
|
|
||
| // This header is available in the Test module. Import via "@import file_selector_ios.Test;". | ||
| @interface FLTFileSelectorPlugin() <FLTFileSelectorApi, UIDocumentPickerDelegate> | ||
|
|
||
| /** | ||
| * The completion block of a FLTFileSelectorApi request. | ||
| * It is saved and invoked later in a UIDocumentPickerDelegate method. | ||
| */ | ||
| @property(nonatomic) void (^_Nullable pendingCompletion) | ||
| (NSArray<NSString *> *_Nullable, FlutterError *_Nullable); | ||
| /** | ||
|
||
| * Overrides the view controller used for presenting the document picker. | ||
| */ | ||
| @property(nonatomic) UIViewController * _Nullable presentingViewControllerOverride; | ||
|
|
||
| /** | ||
| * Overrides the UIDocumentPickerViewController used for file picking. | ||
| */ | ||
| @property(nonatomic) UIDocumentPickerViewController *_Nullable documentPickerViewControllerOverride; | ||
|
|
||
| @end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| framework module file_selector_ios { | ||
| umbrella header "file_selector_ios-umbrella.h" | ||
|
|
||
| export * | ||
| module * { export * } | ||
|
|
||
| explicit module Test { | ||
| header "FLTFileSelectorPlugin_Test.h" | ||
| } | ||
| } | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #import <Foundation/Foundation.h> | ||
| #import <file_selector_ios/FLTFileSelectorPlugin.h> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ Displays the native iOS document picker. | |
| s.author = { 'Flutter Dev Team' => '[email protected]' } | ||
| s.source = { :http => 'https://github.com/flutter/plugins/tree/main/packages/file_selector/file_selector_ios' } | ||
| s.source_files = 'Classes/**/*' | ||
stuartmorgan-g marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| s.module_map = 'Classes/FileSelectorPlugin.modulemap' | ||
| s.dependency 'Flutter' | ||
| s.platform = :ios, '9.0' | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this 11 rather than 9 (and commented out)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I honestly don't remember. It's reverted back to default (and commented out) now and I'm not seeing any issues.