Merge pull request #9 from miguelpruivo/Any-Type-Support
adds iOS support
This commit is contained in:
commit
64b6e79c3d
|
@ -270,7 +270,7 @@
|
|||
};
|
||||
AB4C7D1508951531E70F0A36 /* [CP] Embed Pods Frameworks */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
buildActionMask = 8;
|
||||
files = (
|
||||
);
|
||||
inputPaths = (
|
||||
|
@ -281,7 +281,7 @@
|
|||
outputPaths = (
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
runOnlyForDeploymentPostprocessing = 1;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
|
||||
showEnvVarsInLog = 0;
|
||||
|
@ -441,7 +441,7 @@
|
|||
"$(inherited)",
|
||||
"$(PROJECT_DIR)/Flutter",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.mr.flutter.plugin.filePickerExamples;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.mr.flutter.plugin.filepickerdemo;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
};
|
||||
|
@ -465,7 +465,7 @@
|
|||
"$(inherited)",
|
||||
"$(PROJECT_DIR)/Flutter",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.mr.flutter.plugin.filePickerExamples;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.mr.flutter.plugin.filepickerdemo;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
};
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
language = ""
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
|
@ -46,7 +45,6 @@
|
|||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
language = ""
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#import <Flutter/Flutter.h>
|
||||
|
||||
@interface FilePickerPlugin : NSObject<FlutterPlugin>
|
||||
@interface FilePickerPlugin : NSObject<FlutterPlugin, UIDocumentPickerDelegate>
|
||||
@end
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
#import "FilePickerPlugin.h"
|
||||
|
||||
@implementation FilePickerPlugin
|
||||
FlutterResult _result;
|
||||
UIViewController *_viewController;
|
||||
UIDocumentPickerViewController *_pickerController;
|
||||
UIDocumentInteractionController *_interactionController;
|
||||
@interface FilePickerPlugin()
|
||||
@property (nonatomic) FlutterResult result;
|
||||
@property (nonatomic) UIViewController *viewController;
|
||||
@property (nonatomic) UIDocumentPickerViewController *pickerController;
|
||||
@property (nonatomic) UIDocumentInteractionController *interactionController;
|
||||
@property (nonatomic) NSString * fileType;
|
||||
@end
|
||||
|
||||
@implementation FilePickerPlugin
|
||||
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
|
||||
|
||||
FlutterMethodChannel* channel = [FlutterMethodChannel
|
||||
|
@ -18,17 +21,38 @@
|
|||
[registrar addMethodCallDelegate:instance channel:channel];
|
||||
}
|
||||
|
||||
|
||||
- (instancetype)initWithViewController:(UIViewController *)viewController {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_viewController = viewController;
|
||||
_pickerController = [[UIDocumentPickerViewController alloc]
|
||||
initWithDocumentTypes:@[@"com.adobe.pdf"]
|
||||
inMode:UIDocumentPickerModeImport];
|
||||
if(self){
|
||||
self.viewController = viewController;
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSString*) resolveType:(NSString*)type {
|
||||
|
||||
if ([type isEqualToString:@"PDF"]) {
|
||||
return @"com.adobe.pdf";
|
||||
}
|
||||
else if ([type isEqualToString:@"ANY"]) {
|
||||
return @"public.item";
|
||||
} else {
|
||||
return nil;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (void)initPicker {
|
||||
self.pickerController = [[UIDocumentPickerViewController alloc]
|
||||
initWithDocumentTypes:@[self.fileType]
|
||||
inMode:UIDocumentPickerModeImport];
|
||||
|
||||
self.pickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
|
||||
self.pickerController.delegate = self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
|
||||
if (_result) {
|
||||
_result([FlutterError errorWithCode:@"multiple_request"
|
||||
|
@ -37,29 +61,28 @@
|
|||
_result = nil;
|
||||
}
|
||||
|
||||
self.fileType = [self resolveType:call.method];
|
||||
|
||||
if ([@"pickPDF" isEqualToString:call.method]) {
|
||||
|
||||
_pickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
|
||||
_pickerController.delegate = self;
|
||||
if(self.fileType == nil){
|
||||
result(FlutterMethodNotImplemented);
|
||||
} else {
|
||||
|
||||
[self initPicker];
|
||||
_result = result;
|
||||
[_viewController presentViewController:_pickerController animated:YES completion:^{
|
||||
[_viewController presentViewController:self.pickerController animated:YES completion:^{
|
||||
if (@available(iOS 11.0, *)) {
|
||||
_pickerController.allowsMultipleSelection = NO;
|
||||
self.pickerController.allowsMultipleSelection = NO;
|
||||
}
|
||||
}];
|
||||
|
||||
}
|
||||
else {
|
||||
result(FlutterMethodNotImplemented);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (void)documentPicker:(UIDocumentPickerViewController *)controller
|
||||
didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls{
|
||||
|
||||
[_pickerController dismissViewControllerAnimated:YES completion:nil];
|
||||
[self.pickerController dismissViewControllerAnimated:YES completion:nil];
|
||||
|
||||
NSString * uri;
|
||||
|
||||
|
|
Loading…
Reference in New Issue