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 */ = {
|
AB4C7D1508951531E70F0A36 /* [CP] Embed Pods Frameworks */ = {
|
||||||
isa = PBXShellScriptBuildPhase;
|
isa = PBXShellScriptBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 8;
|
||||||
files = (
|
files = (
|
||||||
);
|
);
|
||||||
inputPaths = (
|
inputPaths = (
|
||||||
|
@ -281,7 +281,7 @@
|
||||||
outputPaths = (
|
outputPaths = (
|
||||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
|
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 1;
|
||||||
shellPath = /bin/sh;
|
shellPath = /bin/sh;
|
||||||
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
|
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
|
||||||
showEnvVarsInLog = 0;
|
showEnvVarsInLog = 0;
|
||||||
|
@ -441,7 +441,7 @@
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"$(PROJECT_DIR)/Flutter",
|
"$(PROJECT_DIR)/Flutter",
|
||||||
);
|
);
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.mr.flutter.plugin.filePickerExamples;
|
PRODUCT_BUNDLE_IDENTIFIER = com.mr.flutter.plugin.filepickerdemo;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
VERSIONING_SYSTEM = "apple-generic";
|
VERSIONING_SYSTEM = "apple-generic";
|
||||||
};
|
};
|
||||||
|
@ -465,7 +465,7 @@
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"$(PROJECT_DIR)/Flutter",
|
"$(PROJECT_DIR)/Flutter",
|
||||||
);
|
);
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.mr.flutter.plugin.filePickerExamples;
|
PRODUCT_BUNDLE_IDENTIFIER = com.mr.flutter.plugin.filepickerdemo;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
VERSIONING_SYSTEM = "apple-generic";
|
VERSIONING_SYSTEM = "apple-generic";
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
buildConfiguration = "Debug"
|
buildConfiguration = "Debug"
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
language = ""
|
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||||
<Testables>
|
<Testables>
|
||||||
</Testables>
|
</Testables>
|
||||||
|
@ -46,7 +45,6 @@
|
||||||
buildConfiguration = "Debug"
|
buildConfiguration = "Debug"
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
language = ""
|
|
||||||
launchStyle = "0"
|
launchStyle = "0"
|
||||||
useCustomWorkingDirectory = "NO"
|
useCustomWorkingDirectory = "NO"
|
||||||
ignoresPersistentStateOnLaunch = "NO"
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#import <Flutter/Flutter.h>
|
#import <Flutter/Flutter.h>
|
||||||
|
|
||||||
@interface FilePickerPlugin : NSObject<FlutterPlugin>
|
@interface FilePickerPlugin : NSObject<FlutterPlugin, UIDocumentPickerDelegate>
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -1,34 +1,58 @@
|
||||||
#import "FilePickerPlugin.h"
|
#import "FilePickerPlugin.h"
|
||||||
|
|
||||||
@implementation FilePickerPlugin
|
@interface FilePickerPlugin()
|
||||||
FlutterResult _result;
|
@property (nonatomic) FlutterResult result;
|
||||||
UIViewController *_viewController;
|
@property (nonatomic) UIViewController *viewController;
|
||||||
UIDocumentPickerViewController *_pickerController;
|
@property (nonatomic) UIDocumentPickerViewController *pickerController;
|
||||||
UIDocumentInteractionController *_interactionController;
|
@property (nonatomic) UIDocumentInteractionController *interactionController;
|
||||||
|
@property (nonatomic) NSString * fileType;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation FilePickerPlugin
|
||||||
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
|
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
|
||||||
|
|
||||||
FlutterMethodChannel* channel = [FlutterMethodChannel
|
FlutterMethodChannel* channel = [FlutterMethodChannel
|
||||||
methodChannelWithName:@"file_picker"
|
methodChannelWithName:@"file_picker"
|
||||||
binaryMessenger:[registrar messenger]];
|
binaryMessenger:[registrar messenger]];
|
||||||
|
|
||||||
UIViewController *viewController = [UIApplication sharedApplication].delegate.window.rootViewController;
|
UIViewController *viewController = [UIApplication sharedApplication].delegate.window.rootViewController;
|
||||||
FilePickerPlugin* instance = [[FilePickerPlugin alloc] initWithViewController:viewController];
|
FilePickerPlugin* instance = [[FilePickerPlugin alloc] initWithViewController:viewController];
|
||||||
|
|
||||||
[registrar addMethodCallDelegate:instance channel:channel];
|
[registrar addMethodCallDelegate:instance channel:channel];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (instancetype)initWithViewController:(UIViewController *)viewController {
|
- (instancetype)initWithViewController:(UIViewController *)viewController {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self) {
|
if(self){
|
||||||
_viewController = viewController;
|
self.viewController = viewController;
|
||||||
_pickerController = [[UIDocumentPickerViewController alloc]
|
|
||||||
initWithDocumentTypes:@[@"com.adobe.pdf"]
|
|
||||||
inMode:UIDocumentPickerModeImport];
|
|
||||||
}
|
}
|
||||||
return self;
|
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 {
|
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
|
||||||
if (_result) {
|
if (_result) {
|
||||||
_result([FlutterError errorWithCode:@"multiple_request"
|
_result([FlutterError errorWithCode:@"multiple_request"
|
||||||
|
@ -36,37 +60,36 @@
|
||||||
details:nil]);
|
details:nil]);
|
||||||
_result = nil;
|
_result = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.fileType = [self resolveType:call.method];
|
||||||
if ([@"pickPDF" isEqualToString:call.method]) {
|
|
||||||
|
if(self.fileType == nil){
|
||||||
_pickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
|
result(FlutterMethodNotImplemented);
|
||||||
_pickerController.delegate = self;
|
} else {
|
||||||
|
|
||||||
_result = result;
|
[self initPicker];
|
||||||
[_viewController presentViewController:_pickerController animated:YES completion:^{
|
_result = result;
|
||||||
if (@available(iOS 11.0, *)) {
|
[_viewController presentViewController:self.pickerController animated:YES completion:^{
|
||||||
_pickerController.allowsMultipleSelection = NO;
|
if (@available(iOS 11.0, *)) {
|
||||||
}
|
self.pickerController.allowsMultipleSelection = NO;
|
||||||
}];
|
}
|
||||||
|
}];
|
||||||
}
|
|
||||||
else {
|
}
|
||||||
result(FlutterMethodNotImplemented);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)documentPicker:(UIDocumentPickerViewController *)controller
|
- (void)documentPicker:(UIDocumentPickerViewController *)controller
|
||||||
didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls{
|
didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls{
|
||||||
|
|
||||||
[_pickerController dismissViewControllerAnimated:YES completion:nil];
|
[self.pickerController dismissViewControllerAnimated:YES completion:nil];
|
||||||
|
|
||||||
NSString * uri;
|
NSString * uri;
|
||||||
|
|
||||||
for (NSURL *url in urls) {
|
for (NSURL *url in urls) {
|
||||||
uri = (NSString *)[url path];
|
uri = (NSString *)[url path];
|
||||||
}
|
}
|
||||||
|
|
||||||
_result(uri);
|
_result(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,12 +105,12 @@ didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls{
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application {
|
- (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application {
|
||||||
|
|
||||||
NSLog(@"Starting to send this puppy to %@", application);
|
NSLog(@"Starting to send this puppy to %@", application);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)documentInteractionController:(UIDocumentInteractionController *)controller didEndSendingToApplication:(NSString *)application {
|
- (void)documentInteractionController:(UIDocumentInteractionController *)controller didEndSendingToApplication:(NSString *)application {
|
||||||
|
|
||||||
NSLog(@"We're done sending the document.");
|
NSLog(@"We're done sending the document.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue