diff --git a/CHANGELOG.md b/CHANGELOG.md index 7aa4ee37..b60bbadb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 4.6.0 + +#### iOS +Add conditional compilation of media, audio and document pickers for iOS. +This prevents error messages for permissions (NSPhotoLibraryUsageDescription, NSAppleMusicUsageDescription, etc.) when publishing to app store connect, in case you don't need either category. This addresses [#783](https://github.com/miguelpruivo/flutter_file_picker/issues/783) in a different way. + ## 4.5.1 #### Web diff --git a/ios/Classes/FilePickerPlugin.h b/ios/Classes/FilePickerPlugin.h index 9b2b7d4e..da0694e9 100644 --- a/ios/Classes/FilePickerPlugin.h +++ b/ios/Classes/FilePickerPlugin.h @@ -4,14 +4,23 @@ #import #import -#if __has_include() || __has_include("PHPicker.h") +#if PICKER_MEDIA && (__has_include() || __has_include("PHPicker.h")) #define PHPicker #import #endif -@interface FilePickerPlugin : NSObject @end diff --git a/ios/Classes/FilePickerPlugin.m b/ios/Classes/FilePickerPlugin.m index c0f3e80c..f09f63ae 100644 --- a/ios/Classes/FilePickerPlugin.m +++ b/ios/Classes/FilePickerPlugin.m @@ -2,14 +2,22 @@ #import "FileUtils.h" #import "ImageUtils.h" +#ifdef PICKER_MEDIA @import DKImagePickerController; @interface FilePickerPlugin() +#else +@interface FilePickerPlugin() +#endif @property (nonatomic) FlutterResult result; @property (nonatomic) FlutterEventSink eventSink; +#ifdef PICKER_MEDIA @property (nonatomic) UIImagePickerController *galleryPickerController; +#endif +#ifdef PICKER_DOCUMENT @property (nonatomic) UIDocumentPickerViewController *documentPickerController; @property (nonatomic) UIDocumentInteractionController *interactionController; +#endif @property (nonatomic) MPMediaPickerController *audioPickerController; @property (nonatomic) NSArray * allowedExtensions; @property (nonatomic) BOOL loadDataToMemory; @@ -87,7 +95,13 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { if([call.method isEqualToString:@"dir"]) { if (@available(iOS 13, *)) { +#ifdef PICKER_DOCUMENT [self resolvePickDocumentWithMultiPick:NO pickDirectory:YES]; +#else + _result([FlutterError errorWithCode:@"Unsupported picker type" + message:@"Support for the Document picker is not compiled in. Remove the Pod::PICKER_DOCUMENT=false statement from your Podfile." + details:nil]); +#endif } else { _result([self getDocumentDirectory]); _result = nil; @@ -109,12 +123,30 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { details:nil]); _result = nil; } else if(self.allowedExtensions != nil) { +#ifdef PICKER_DOCUMENT [self resolvePickDocumentWithMultiPick:isMultiplePick pickDirectory:NO]; +#else + _result([FlutterError errorWithCode:@"Unsupported picker type" + message:@"Support for the Document picker is not compiled in. Remove the Pod::PICKER_DOCUMENT=false statement from your Podfile." + details:nil]); +#endif } } else if([call.method isEqualToString:@"video"] || [call.method isEqualToString:@"image"] || [call.method isEqualToString:@"media"]) { +#ifdef PICKER_MEDIA [self resolvePickMedia:[FileUtils resolveMediaType:call.method] withMultiPick:isMultiplePick withCompressionAllowed:self.allowCompression]; +#else + _result([FlutterError errorWithCode:@"Unsupported picker type" + message:@"Support for the Media picker is not compiled in. Remove the Pod::PICKER_MEDIA=false statement from your Podfile." + details:nil]); +#endif } else if([call.method isEqualToString:@"audio"]) { - [self resolvePickAudioWithMultiPick: isMultiplePick]; + #ifdef PICKER_AUDIO + [self resolvePickAudioWithMultiPick: isMultiplePick]; + #else + _result([FlutterError errorWithCode:@"Unsupported picker type" + message:@"Support for the Audio picker is not compiled in. Remove the Pod::PICKER_AUDIO=false statement from your Podfile." + details:nil]); +#endif } else { result(FlutterMethodNotImplemented); _result = nil; @@ -127,6 +159,8 @@ - (NSString*)getDocumentDirectory { } #pragma mark - Resolvers + +#ifdef PICKER_DOCUMENT - (void)resolvePickDocumentWithMultiPick:(BOOL)allowsMultipleSelection pickDirectory:(BOOL)isDirectory { @try{ @@ -150,7 +184,9 @@ - (void)resolvePickDocumentWithMultiPick:(BOOL)allowsMultipleSelection pickDirec [[self viewControllerWithWindow:nil] presentViewController:self.documentPickerController animated:YES completion:nil]; } +#endif // PICKER_DOCUMENT +#ifdef PICKER_MEDIA - (void) resolvePickMedia:(MediaType)type withMultiPick:(BOOL)multiPick withCompressionAllowed:(BOOL)allowCompression { #ifdef PHPicker @@ -285,7 +321,9 @@ - (void) resolveMultiPickFromGallery:(MediaType)type withCompressionAllowed:(BOO [[self viewControllerWithWindow:nil] presentViewController:dkImagePickerController animated:YES completion:nil]; } +#endif // PICKER_MEDIA +#ifdef PICKER_AUDIO - (void) resolvePickAudioWithMultiPick:(BOOL)isMultiPick { @@ -304,6 +342,8 @@ - (void) resolvePickAudioWithMultiPick:(BOOL)isMultiPick { [[self viewControllerWithWindow:nil] presentViewController:self.audioPickerController animated:YES completion:nil]; } +#endif // PICKER_AUDIO + - (void) handleResult:(id) files { _result([FileUtils resolveFileInfo: [files isKindOfClass: [NSArray class]] ? files : @[files] withData:self.loadDataToMemory]); @@ -312,6 +352,7 @@ - (void) handleResult:(id) files { #pragma mark - Delegates +#ifdef PICKER_DOCUMENT // DocumentPicker delegate - iOS 10 only - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url{ [self.documentPickerController dismissViewControllerAnimated:YES completion:nil]; @@ -336,8 +377,9 @@ - (void)documentPicker:(UIDocumentPickerViewController *)controller [self handleResult: urls]; } +#endif // PICKER_DOCUMENT - +#ifdef PICKER_MEDIA // ImagePicker delegate - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { if(_result == nil) { @@ -503,9 +545,10 @@ -(void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray '../LICENSE' } - s.author = { 'Your Company' => 'email@example.com' } - s.source = { :path => '.' } - s.source_files = 'Classes/**/*' - s.public_header_files = 'Classes/**/*.h' - s.dependency 'Flutter' - s.dependency 'DKImagePickerController/PhotoGallery' + s.homepage = 'https://github.com/miguelpruivo/plugins_flutter_file_picker' + s.license = { :file => '../LICENSE' } + s.author = 'Miguel Ruivo' + s.source = { :path => '.' } + s.source_files = 'Classes/**/*' + s.public_header_files = 'Classes/**/*.h' + s.ios.deployment_target = '8.0' + + s.dependency 'Flutter' + + preprocess_definitions=[] + if !Pod.const_defined?(:PICKER_MEDIA) || PICKER_MEDIA + preprocess_definitions << ["PICKER_MEDIA=1"] + s.dependency 'DKImagePickerController/PhotoGallery' + end + if !Pod.const_defined?(:PICKER_AUDIO) || PICKER_AUDIO + preprocess_definitions << ["PICKER_AUDIO=1"] + end + if !Pod.const_defined?(:PICKER_DOCUMENT) || PICKER_DOCUMENT + preprocess_definitions << ["PICKER_DOCUMENT=1"] + end + s.pod_target_xcconfig = { "GCC_PREPROCESSOR_DEFINITIONS" => preprocess_definitions } + end diff --git a/pubspec.yaml b/pubspec.yaml index 76ae357b..4a0ca833 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: A package that allows you to use a native file explorer to pick sin homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker repository: https://github.com/miguelpruivo/flutter_file_picker issue_tracker: https://github.com/miguelpruivo/flutter_file_picker/issues -version: 4.5.1 +version: 4.6.0 dependencies: flutter: