adds iOS support

This commit is contained in:
Miguel Ruivo 2018-11-30 18:06:11 +00:00
parent 2aa8ba18f5
commit c5b68029ce
4 changed files with 69 additions and 48 deletions

View File

@ -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";
};

View File

@ -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"

View File

@ -1,4 +1,4 @@
#import <Flutter/Flutter.h>
@interface FilePickerPlugin : NSObject<FlutterPlugin>
@interface FilePickerPlugin : NSObject<FlutterPlugin, UIDocumentPickerDelegate>
@end

View File

@ -1,34 +1,58 @@
#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
methodChannelWithName:@"file_picker"
binaryMessenger:[registrar messenger]];
FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"file_picker"
binaryMessenger:[registrar messenger]];
UIViewController *viewController = [UIApplication sharedApplication].delegate.window.rootViewController;
FilePickerPlugin* instance = [[FilePickerPlugin alloc] initWithViewController:viewController];
[registrar addMethodCallDelegate:instance channel:channel];
[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"
@ -36,37 +60,36 @@
details:nil]);
_result = nil;
}
if ([@"pickPDF" isEqualToString:call.method]) {
_pickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
_pickerController.delegate = self;
_result = result;
[_viewController presentViewController:_pickerController animated:YES completion:^{
if (@available(iOS 11.0, *)) {
_pickerController.allowsMultipleSelection = NO;
}
}];
}
else {
result(FlutterMethodNotImplemented);
}
self.fileType = [self resolveType:call.method];
if(self.fileType == nil){
result(FlutterMethodNotImplemented);
} else {
[self initPicker];
_result = result;
[_viewController presentViewController:self.pickerController animated:YES completion:^{
if (@available(iOS 11.0, *)) {
self.pickerController.allowsMultipleSelection = NO;
}
}];
}
}
- (void)documentPicker:(UIDocumentPickerViewController *)controller
didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls{
[_pickerController dismissViewControllerAnimated:YES completion:nil];
[self.pickerController dismissViewControllerAnimated:YES completion:nil];
NSString * uri;
for (NSURL *url in urls) {
uri = (NSString *)[url path];
uri = (NSString *)[url path];
}
_result(uri);
}
@ -82,12 +105,12 @@ didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls{
}
- (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application {
NSLog(@"Starting to send this puppy to %@", application);
}
- (void)documentInteractionController:(UIDocumentInteractionController *)controller didEndSendingToApplication:(NSString *)application {
NSLog(@"We're done sending the document.");
}