From 151e0fa7ada379db4b3215d2236c5e400bcdc332 Mon Sep 17 00:00:00 2001 From: rajesh1158 Date: Sat, 5 Oct 2019 18:13:35 +0530 Subject: [PATCH] added support for plugin option maxSelectSize for iOS --- src/ios/DMCMediaPicker/.DS_Store | Bin 8196 -> 10244 bytes .../DMCMediaPicker/DmcPickerViewController.h | 1 + .../DMCMediaPicker/DmcPickerViewController.m | 58 +++++++++++++++--- .../de.lproj/Localizable.strings | 5 +- .../en.lproj/Localizable.strings | 3 +- .../es.lproj/Localizable.strings | 3 +- .../pt-BR.lproj/Localizable.strings | 3 +- .../pt-PT.lproj/Localizable.strings | 3 +- .../tr.lproj/Localizable.strings | 3 +- .../zh-Hans.lproj/Localizable.strings | 3 +- src/ios/MediaPicker.m | 5 ++ 11 files changed, 72 insertions(+), 15 deletions(-) diff --git a/src/ios/DMCMediaPicker/.DS_Store b/src/ios/DMCMediaPicker/.DS_Store index 3bf546f79516248ef598d1c50f16c13287ee4f0e..573bd77866aad86899b1437e8d276dbdf4eeab24 100644 GIT binary patch literal 10244 zcmeHM-A)rh6g~r}3rOe%33|7QG2sG9Nl`A0NhxR~@q$=_7iyrT4P9+_NxP*=t?7;L zpuT~R;uH8FK7f8_X2I@kcQ;C6U^A1%c|20FYC7EECG`10=={WHFFKB_$MXD(^uAP!YHoLcvjQvpQrk zkV7REoP>gt2znNQhazO}z}ZrrL{Uj|H4GRAq71O_K2ICeq$+ho{<}kU>d^`{wwvBz zwdqx%$&2eD^3pGvP)b9$H1szOy+E7fq4y?wJ4D>T!JUiff$Dt|Pq{8K3bFW)?P%i> zpR{%?s-e#n^m$BejO9&u{NiVtezn&*4%qr$J#IQ3KcD|0CMKt@UB6*jGuF)9%y`bA-|dtt?U#JFQ}G+spuFpO>}ly64n;`?-Zp&-E*gTW?FSQ>#Pe)eFb1dA*X? zb!#2jPFYo0*0eRfpS#uX7Yg^6?ZVpnVA<}kujiNTwZenJVA@)|yZUJRp!NQ=|6%a) z3nqmmg1r?65l&xm8zJVT+;*Fud&EHG9EfY-74G2G9nxEn*anSkR4!`pdc#CYGx|JY zMz?7zg8yR%Y!tqHA<9&^ZQU^0v@X`7ZX9f6qb*vPm78E3Y)pyz*)p`N(e4891khO@wnk|{1P(j=2>z=xfsZyl6Zpj z-+u;NqNth{7|}j6Qe4?+OfBTfrJ%F=6_+w?jpBGOeoTNdL~lG&_p#YK84b)_0{{Ov D@k1}X delta 273 zcmZn(XmOBWU|?W$DortDU;r^WfEYvza8E20o2aMAD6}zPH$S7$W*z~4#>pW<`jf2$ z1%b38Pg!tLUQT{qI!OQIi9#-HOo>3I#^l>VK5R_q!AxCYEk0&j5c5A6FfdHc6H#Jg zUJaJLE2=g5q$nR7izJw9Bd$7GU7Vkdr5(yOncOTSIJr^WcJfs)tvC6vxWHr$VS&lP z65^9}1ov%eu1(|_n0)YfKkZ=Y0 YZe!th=E?jjfgFqwKQnBO=b6I{0JRW9YXATM diff --git a/src/ios/DMCMediaPicker/DmcPickerViewController.h b/src/ios/DMCMediaPicker/DmcPickerViewController.h index dca9200..aa91a1b 100644 --- a/src/ios/DMCMediaPicker/DmcPickerViewController.h +++ b/src/ios/DMCMediaPicker/DmcPickerViewController.h @@ -17,4 +17,5 @@ @property (nonatomic, assign) NSInteger maxSelectCount; //'selectMode':101,//101=PICKER_IMAGE_VIDEO , 100=PICKER_IMAGE , 102=PICKER_VIDEO @property (nonatomic, assign) NSInteger selectMode; +@property (nonatomic, assign) NSInteger maxSelectSize; @end diff --git a/src/ios/DMCMediaPicker/DmcPickerViewController.m b/src/ios/DMCMediaPicker/DmcPickerViewController.m index 91ee2cd..d55eadc 100644 --- a/src/ios/DMCMediaPicker/DmcPickerViewController.m +++ b/src/ios/DMCMediaPicker/DmcPickerViewController.m @@ -29,6 +29,7 @@ - (void)viewDidLoad { //init config self.maxSelectCount=self.maxSelectCount>0?self.maxSelectCount:15; + self.maxSelectSize=self.maxSelectSize>0?self.maxSelectSize:1048576; self.selectMode=self.selectMode>0?self.selectMode:101; //config end @@ -379,12 +380,14 @@ NSInteger i=[self isSelect:asset]; CollectionViewCell *cell = (CollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath]; - if([selectArray count]>=self.maxSelectCount&&i<0){ + if([selectArray count] >= self.maxSelectCount && i < 0){ [self alertMax]; }else{ - if([selectArray count]>self.maxSelectCount){ + if([selectArray count] > self.maxSelectCount){ [self alertMax]; - }else{ + }else if([self assetFileSize:asset] > self.maxSelectSize) { + [self alertSize]; + } else { i<0?[selectArray addObject:asset]:[selectArray removeObject:asset]; i<0?[self showSelectView:cell]:[self hidenSelectView:cell]; } @@ -429,7 +432,40 @@ [self._delegate resultPicker:srray]; [self dismissViewControllerAnimated:YES completion:nil]; } - + +-(long) assetFileSize:(PHAsset *)asset +{ + __block long imageSize = 0; + + if(asset.mediaType == PHAssetMediaTypeVideo) { + PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init]; + options.version = PHVideoRequestOptionsVersionOriginal; + + [[PHImageManager defaultManager] requestAVAssetForVideo:asset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) { + if([asset isKindOfClass:[AVURLAsset class]]) { + AVURLAsset* urlAsset = (AVURLAsset*)asset; + NSNumber *size; + + [urlAsset.URL getResourceValue:&size forKey:NSURLFileSizeKey error:nil]; + NSLog(@"%lu", (unsigned long)size); + imageSize = (unsigned long)size; + } + }]; + } else { + // Fetch image data to retrieve file size and path + PHImageRequestOptions * options = [[PHImageRequestOptions alloc] init]; + options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat; + options.resizeMode = PHImageRequestOptionsResizeModeExact; + options.synchronous = YES; //Set this to NO if is needed + + [[PHImageManager defaultManager] requestImageDataForAsset:asset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { + NSLog(@"%lu", (unsigned long)imageData.length); + imageSize = (unsigned long)imageData.length; + }]; + } + return imageSize; +} + -(NSInteger)isSelect:(PHAsset *)asset { int is=-1; @@ -450,15 +486,23 @@ } -(void)alertMax{ - UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" - message:NSLocalizedString(@"maxSelectAlert",nil) - preferredStyle:UIAlertControllerStyleAlert]; + NSString *message = [NSString stringWithFormat:NSLocalizedString(@"maxSelectAlert", nil), self.maxSelectCount]; + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:message preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"ok",nil) style:UIAlertActionStyleDefault handler:nil]; [alertController addAction:okAction]; [self presentViewController:alertController animated:YES completion:nil]; } + +-(void)alertSize{ + NSString *message = [NSString stringWithFormat:NSLocalizedString(@"maxSizeAlert", nil), (float)self.maxSelectSize/1048576]; + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:message preferredStyle:UIAlertControllerStyleAlert]; + UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"ok",nil) style:UIAlertActionStyleDefault handler:nil]; + [alertController addAction:okAction]; + [self presentViewController:alertController animated:YES completion:nil]; +} + - (NSString *)getNewTimeFromDurationSecond:(NSInteger)duration { NSString *newTime; if (duration < 10) { diff --git a/src/ios/DMCMediaPicker/de.lproj/Localizable.strings b/src/ios/DMCMediaPicker/de.lproj/Localizable.strings index 91088ad..49bde23 100644 --- a/src/ios/DMCMediaPicker/de.lproj/Localizable.strings +++ b/src/ios/DMCMediaPicker/de.lproj/Localizable.strings @@ -3,9 +3,10 @@ "Back"="Zurück"; "All"="Alle Fotos"; "Video"="Video"; -"maxSelectAlert"="Maximale Anzahl erreicht"; +"maxSelectAlert"="Sie können nur %d Bilder auswählen"; +"maxSizeAlert"="Sie können nur Bilder mit einer Größe von bis zu %.02f MB auswählen"; "ok"="OK"; "Unable to access album" = "Auf Album kann nicht zugegriffen werden"; "Please allow to access your album" = "Bitte erlaube den Zugriff auf Dein Album in \"Einstellungen -> Datenschutz -> Fotos\""; "Setting" = "Einstellungen"; -"Preview" = "Vorschau"; \ No newline at end of file +"Preview" = "Vorschau"; diff --git a/src/ios/DMCMediaPicker/en.lproj/Localizable.strings b/src/ios/DMCMediaPicker/en.lproj/Localizable.strings index 501660a..d7a9e22 100644 --- a/src/ios/DMCMediaPicker/en.lproj/Localizable.strings +++ b/src/ios/DMCMediaPicker/en.lproj/Localizable.strings @@ -2,8 +2,9 @@ "Done"="Done"; "All"="All photos"; "Video"="Video"; -"maxSelectAlert"="Has reached the maximum number of choices"; "ok"="OK"; +"maxSelectAlert"="You can only select %d images"; +"maxSizeAlert"="You can only select images up to %.02f mb in size"; "Unable to access album" = "Unable to access album"; "Please allow to access your album" = "Please allow to access your album in \"Settings -> Privacy -> Album\""; "Setting" = "Setting"; diff --git a/src/ios/DMCMediaPicker/es.lproj/Localizable.strings b/src/ios/DMCMediaPicker/es.lproj/Localizable.strings index ccdba9c..e50b1f6 100644 --- a/src/ios/DMCMediaPicker/es.lproj/Localizable.strings +++ b/src/ios/DMCMediaPicker/es.lproj/Localizable.strings @@ -2,7 +2,8 @@ "Done"="hecho"; "All"="Todas las fotos"; "Video"="Video"; -"maxSelectAlert"="Has alcanzado el número maximo de selecciones"; +"maxSelectAlert"="Solo puedes seleccionar %d imágenes"; +"maxSizeAlert"="Solo puede seleccionar imágenes de hasta %.02f mb de tamaño"; "ok"="OK"; "Unable to access album" = "Denegado el acceso al album"; "Please allow to access your album" = "Por favor permita el acceso a sus albums en \"Configuraciones -> Privacidad -> Album\""; diff --git a/src/ios/DMCMediaPicker/pt-BR.lproj/Localizable.strings b/src/ios/DMCMediaPicker/pt-BR.lproj/Localizable.strings index 9451ca5..e4e2793 100644 --- a/src/ios/DMCMediaPicker/pt-BR.lproj/Localizable.strings +++ b/src/ios/DMCMediaPicker/pt-BR.lproj/Localizable.strings @@ -2,7 +2,8 @@ "Done"="Pronto"; "All"="Todas as fotos"; "Video"="Vídeo"; -"maxSelectAlert"="Atingiu o limite máximo de escolhas"; +"maxSelectAlert"="Você só pode selecionar %d imagens"; +"maxSizeAlert"="Você só pode selecionar imagens com tamanho de até %.02f mb"; "ok"="OK"; "Unable to access album" = "Impossibilitado de acessar o álbum"; "Please allow to access your album" = "Por favor permita acessar o seu álbum em \“Configurações -> Privacidade -> Álbum\""; diff --git a/src/ios/DMCMediaPicker/pt-PT.lproj/Localizable.strings b/src/ios/DMCMediaPicker/pt-PT.lproj/Localizable.strings index 9451ca5..e4e2793 100644 --- a/src/ios/DMCMediaPicker/pt-PT.lproj/Localizable.strings +++ b/src/ios/DMCMediaPicker/pt-PT.lproj/Localizable.strings @@ -2,7 +2,8 @@ "Done"="Pronto"; "All"="Todas as fotos"; "Video"="Vídeo"; -"maxSelectAlert"="Atingiu o limite máximo de escolhas"; +"maxSelectAlert"="Você só pode selecionar %d imagens"; +"maxSizeAlert"="Você só pode selecionar imagens com tamanho de até %.02f mb"; "ok"="OK"; "Unable to access album" = "Impossibilitado de acessar o álbum"; "Please allow to access your album" = "Por favor permita acessar o seu álbum em \“Configurações -> Privacidade -> Álbum\""; diff --git a/src/ios/DMCMediaPicker/tr.lproj/Localizable.strings b/src/ios/DMCMediaPicker/tr.lproj/Localizable.strings index 3ec3750..46fa53e 100644 --- a/src/ios/DMCMediaPicker/tr.lproj/Localizable.strings +++ b/src/ios/DMCMediaPicker/tr.lproj/Localizable.strings @@ -2,7 +2,8 @@ "Done"="Bitti"; "All"="Tümü"; "Video"="Video"; -"maxSelectAlert"="Maksimum seçime ulaşıldı!"; +"maxSelectAlert"="Sadece %d görüntü seçebilirsiniz"; +"maxSizeAlert"="Yalnızca %.02f mb boyutunda olan resimleri seçebilirsiniz"; "ok"="Tamam"; "Unable to access album" = "Galerinize erişilemiyor"; "Please allow to access your album" = "Lütfen \"Ayarlar -> Gizlilik -> Fotoğraflar\" menüsünden uygulamaya erişim izni verin."; diff --git a/src/ios/DMCMediaPicker/zh-Hans.lproj/Localizable.strings b/src/ios/DMCMediaPicker/zh-Hans.lproj/Localizable.strings index 7023dc1..2883c1b 100644 --- a/src/ios/DMCMediaPicker/zh-Hans.lproj/Localizable.strings +++ b/src/ios/DMCMediaPicker/zh-Hans.lproj/Localizable.strings @@ -2,7 +2,8 @@ "Done"="完成"; "All"="所有照片"; "Video"="视频"; -"maxSelectAlert"="已达到选择数量上限"; +"maxSelectAlert"="您只能选择%d张图片"; +"maxSizeAlert"="您只能选择最大%.02f mb的图像"; "ok"="好"; "Unable to access album" = "无法访问相册"; "Please allow to access your album" = "请在设置-隐私-相册中允许访问相册"; diff --git a/src/ios/MediaPicker.m b/src/ios/MediaPicker.m index f71938e..6372f1a 100644 --- a/src/ios/MediaPicker.m +++ b/src/ios/MediaPicker.m @@ -30,6 +30,11 @@ }@catch (NSException *exception) { NSLog(@"Exception: %@", exception); } + @try{ + dmc.maxSelectSize=[[options objectForKey:@"maxSelectSize"]integerValue]; + }@catch (NSException *exception) { + NSLog(@"Exception: %@", exception); + } dmc._delegate=self; [self.viewController presentViewController:[[UINavigationController alloc]initWithRootViewController:dmc] animated:YES completion:nil]; }