diff --git a/README.md b/README.md index e6e6bb042..8bcb00093 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ ImagePicker.clean().then(() => { | cropperStatusBarColor (android only) | string (default `#424242`) | When cropping image, determines the color of StatusBar. | | cropperToolbarColor (android only) | string (default `#424242`) | When cropping image, determines the color of Toolbar. | | cropperCircleOverlay | bool (default false) | Enable or disable circular cropping mask. | +| minFiles (ios only) | number (default 1) | Min number of files to select when using `multiple` option | | maxFiles (ios only) | number (default 5) | Max number of files to select when using `multiple` option | | waitAnimationEnd (ios only) | bool (default true) | Promise will resolve/reject once ViewController `completion` block is called | | smartAlbums (ios only) | array (default ['UserLibrary', 'PhotoStream', 'Panoramas', 'Videos', 'Bursts']) | List of smart albums to choose from | @@ -98,16 +99,17 @@ ImagePicker.clean().then(() => { | enableRotationGesture (android only) | bool (default false) | Whether to enable rotating the image by hand gesture | #### Response Object -| Property | Type | Description | -| --------------- | :----: | :--------------------------------------- | -| path | string | Selected image location | -| localIdentifier | string | Selected images' localidentifier, used for PHAsset searching | -| filename | string | Selected images' filename | -| width | number | Selected image width | -| height | number | Selected image height | -| mime | string | Selected image MIME type (image/jpeg, image/png) | -| size | number | Selected image size in bytes | -| data | base64 | Optional base64 selected file representation | +| Property | Type | Description | +| ------------------------- | :----: | :--------------------------------------- | +| path | string | Selected image location | +| localIdentifier(ios only) | string | Selected images' localidentifier, used for PHAsset searching | +| sourceURL(ios only) | string | Selected images' source path, do not have write access | +| filename(ios only) | string | Selected images' filename | +| width | number | Selected image width | +| height | number | Selected image height | +| mime | string | Selected image MIME type (image/jpeg, image/png) | +| size | number | Selected image size in bytes | +| data | base64 | Optional base64 selected file representation | ## Install diff --git a/ios/ImageCropPicker.m b/ios/ImageCropPicker.m index 143c04038..baf2db04f 100644 --- a/ios/ImageCropPicker.m +++ b/ios/ImageCropPicker.m @@ -52,6 +52,7 @@ - (instancetype)init @"cropperCircleOverlay": @NO, @"includeBase64": @NO, @"compressVideo": @YES, + @"minFiles": @1, @"maxFiles": @5, @"width": @200, @"waitAnimationEnd": @YES, @@ -154,7 +155,7 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking UIImage *chosenImage = [info objectForKey:UIImagePickerControllerOriginalImage]; UIImage *chosenImageT = [chosenImage fixOrientation]; - [self processSingleImagePick:chosenImageT withViewController:picker withLocalIdentifier:self.croppingFile[@"localIdentifier"] withFilename:self.croppingFile[@"filename"]]; + [self processSingleImagePick:chosenImageT withViewController:picker withSourceURL:self.croppingFile[@"sourceURL"] withLocalIdentifier:self.croppingFile[@"localIdentifier"] withFilename:self.croppingFile[@"filename"]]; } - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { @@ -233,7 +234,8 @@ - (BOOL)cleanTmpDirectory { [QBImagePickerController new]; imagePickerController.delegate = self; imagePickerController.allowsMultipleSelection = [[self.options objectForKey:@"multiple"] boolValue]; - imagePickerController.maximumNumberOfSelection = [[self.options objectForKey:@"maxFiles"] intValue]; + imagePickerController.minimumNumberOfSelection = abs([[self.options objectForKey:@"minFiles"] intValue]); + imagePickerController.maximumNumberOfSelection = abs([[self.options objectForKey:@"maxFiles"] intValue]); imagePickerController.showsNumberOfSelectedAssets = [[self.options objectForKey:@"showsSelectedCount"] boolValue]; if ([self.options objectForKey:@"smartAlbums"] != nil) { @@ -375,8 +377,9 @@ - (void) getVideoAsset:(PHAsset*)forAsset completion:(void (^)(NSDictionary* ima error:nil]; completion([self createAttachmentResponse:[outputURL absoluteString] + withSourceURL:[sourceURL absoluteString] withLocalIdentifier: forAsset.localIdentifier - withFilename: sourceURL.lastPathComponent + withFilename:[forAsset valueForKey:@"filename"] withWidth:[NSNumber numberWithFloat:track.naturalSize.width] withHeight:[NSNumber numberWithFloat:track.naturalSize.height] withMime:@"video/mp4" @@ -389,9 +392,10 @@ - (void) getVideoAsset:(PHAsset*)forAsset completion:(void (^)(NSDictionary* ima }]; } -- (NSDictionary*) createAttachmentResponse:(NSString*)filePath withLocalIdentifier:(NSString*)localIdentifier withFilename:(NSString*)filename withWidth:(NSNumber*)width withHeight:(NSNumber*)height withMime:(NSString*)mime withSize:(NSNumber*)size withData:(NSString*)data { +- (NSDictionary*) createAttachmentResponse:(NSString*)filePath withSourceURL:(NSString*)sourceURL withLocalIdentifier:(NSString*)localIdentifier withFilename:(NSString*)filename withWidth:(NSNumber*)width withHeight:(NSNumber*)height withMime:(NSString*)mime withSize:(NSNumber*)size withData:(NSString*)data { return @{ @"path": filePath, + @"sourceURL": (sourceURL) ? sourceURL : @"", @"localIdentifier": (localIdentifier) ? localIdentifier : @"", @"filename": (filename) ? filename : @"", @"width": width, @@ -475,8 +479,9 @@ - (void)qb_imagePickerController: } [selections addObject:[self createAttachmentResponse:filePath + withSourceURL:[sourceURL absoluteString] withLocalIdentifier: phAsset.localIdentifier - withFilename: sourceURL.lastPathComponent + withFilename: [phAsset valueForKey:@"filename"] withWidth:imageResult.width withHeight:imageResult.height withMime:imageResult.mime @@ -530,7 +535,7 @@ - (void)qb_imagePickerController: dispatch_async(dispatch_get_main_queue(), ^{ [indicatorView stopAnimating]; [overlayView removeFromSuperview]; - [self processSingleImagePick:[UIImage imageWithData:imageData] withViewController:imagePickerController withLocalIdentifier:phAsset.localIdentifier withFilename:sourceURL.lastPathComponent]; + [self processSingleImagePick:[UIImage imageWithData:imageData] withViewController:imagePickerController withSourceURL:[sourceURL absoluteString] withLocalIdentifier:phAsset.localIdentifier withFilename:[phAsset valueForKey:@"filename"]]; }); }]; } @@ -547,7 +552,7 @@ - (void)qb_imagePickerControllerDidCancel:(QBImagePickerController *)imagePicker // when user selected single image, with camera or from photo gallery, // this method will take care of attaching image metadata, and sending image to cropping controller // or to user directly -- (void) processSingleImagePick:(UIImage*)image withViewController:(UIViewController*)viewController withLocalIdentifier:(NSString*)localIdentifier withFilename:(NSString*)filename { +- (void) processSingleImagePick:(UIImage*)image withViewController:(UIViewController*)viewController withSourceURL:(NSString*)sourceURL withLocalIdentifier:(NSString*)localIdentifier withFilename:(NSString*)filename { if (image == nil) { [viewController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{ @@ -560,6 +565,7 @@ - (void) processSingleImagePick:(UIImage*)image withViewController:(UIViewContro if ([[[self options] objectForKey:@"cropping"] boolValue]) { self.croppingFile = [[NSMutableDictionary alloc] init]; + self.croppingFile[@"sourceURL"] = sourceURL; self.croppingFile[@"localIdentifier"] = localIdentifier; self.croppingFile[@"filename"] = filename; NSLog(@"CroppingFile %@", self.croppingFile); @@ -579,6 +585,7 @@ - (void) processSingleImagePick:(UIImage*)image withViewController:(UIViewContro // Alert.alert in the .then() handler. [viewController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{ self.resolve([self createAttachmentResponse:filePath + withSourceURL:sourceURL withLocalIdentifier:localIdentifier withFilename:filename withWidth:imageResult.width @@ -690,6 +697,7 @@ - (void)imageCropViewController:(RSKImageCropViewController *)controller [self dismissCropper:controller dismissAll: YES completion:[self waitAnimationEnd:^{ self.resolve([self createAttachmentResponse:filePath + withSourceURL: self.croppingFile[@"sourceURL"] withLocalIdentifier: self.croppingFile[@"localIdentifier"] withFilename: self.croppingFile[@"filename"] withWidth:imageResult.width