mirror of
https://github.com/DmcSDK/cordova-plugin-mediaPicker
synced 2026-04-14 00:03:04 +08:00
Merge pull request #87 from rajesh1158/master
Added support for plugin option maxSelectSize for iOS
This commit is contained in:
Vendored
BIN
Binary file not shown.
@@ -17,4 +17,5 @@
|
|||||||
@property (nonatomic, assign) NSInteger maxSelectCount;
|
@property (nonatomic, assign) NSInteger maxSelectCount;
|
||||||
//'selectMode':101,//101=PICKER_IMAGE_VIDEO , 100=PICKER_IMAGE , 102=PICKER_VIDEO
|
//'selectMode':101,//101=PICKER_IMAGE_VIDEO , 100=PICKER_IMAGE , 102=PICKER_VIDEO
|
||||||
@property (nonatomic, assign) NSInteger selectMode;
|
@property (nonatomic, assign) NSInteger selectMode;
|
||||||
|
@property (nonatomic, assign) NSInteger maxSelectSize;
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
- (void)viewDidLoad {
|
- (void)viewDidLoad {
|
||||||
//init config
|
//init config
|
||||||
self.maxSelectCount=self.maxSelectCount>0?self.maxSelectCount:15;
|
self.maxSelectCount=self.maxSelectCount>0?self.maxSelectCount:15;
|
||||||
|
self.maxSelectSize=self.maxSelectSize>0?self.maxSelectSize:1048576;
|
||||||
self.selectMode=self.selectMode>0?self.selectMode:101;
|
self.selectMode=self.selectMode>0?self.selectMode:101;
|
||||||
//config end
|
//config end
|
||||||
|
|
||||||
@@ -379,12 +380,14 @@
|
|||||||
NSInteger i=[self isSelect:asset];
|
NSInteger i=[self isSelect:asset];
|
||||||
CollectionViewCell *cell = (CollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
|
CollectionViewCell *cell = (CollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
|
||||||
|
|
||||||
if([selectArray count]>=self.maxSelectCount&&i<0){
|
if([selectArray count] >= self.maxSelectCount && i < 0){
|
||||||
[self alertMax];
|
[self alertMax];
|
||||||
}else{
|
}else{
|
||||||
if([selectArray count]>self.maxSelectCount){
|
if([selectArray count] > self.maxSelectCount){
|
||||||
[self alertMax];
|
[self alertMax];
|
||||||
}else{
|
}else if([self assetFileSize:asset] > self.maxSelectSize) {
|
||||||
|
[self alertSize];
|
||||||
|
} else {
|
||||||
i<0?[selectArray addObject:asset]:[selectArray removeObject:asset];
|
i<0?[selectArray addObject:asset]:[selectArray removeObject:asset];
|
||||||
i<0?[self showSelectView:cell]:[self hidenSelectView:cell];
|
i<0?[self showSelectView:cell]:[self hidenSelectView:cell];
|
||||||
}
|
}
|
||||||
@@ -429,7 +432,40 @@
|
|||||||
[self._delegate resultPicker:srray];
|
[self._delegate resultPicker:srray];
|
||||||
[self dismissViewControllerAnimated:YES completion:nil];
|
[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
|
-(NSInteger)isSelect:(PHAsset *)asset
|
||||||
{
|
{
|
||||||
int is=-1;
|
int is=-1;
|
||||||
@@ -450,15 +486,23 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
-(void)alertMax{
|
-(void)alertMax{
|
||||||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@""
|
NSString *message = [NSString stringWithFormat:NSLocalizedString(@"maxSelectAlert", nil), self.maxSelectCount];
|
||||||
message:NSLocalizedString(@"maxSelectAlert",nil)
|
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:message preferredStyle:UIAlertControllerStyleAlert];
|
||||||
preferredStyle:UIAlertControllerStyleAlert];
|
|
||||||
UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"ok",nil) style:UIAlertActionStyleDefault handler:nil];
|
UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"ok",nil) style:UIAlertActionStyleDefault handler:nil];
|
||||||
[alertController addAction:okAction];
|
[alertController addAction:okAction];
|
||||||
|
|
||||||
[self presentViewController:alertController animated:YES completion:nil];
|
[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 *)getNewTimeFromDurationSecond:(NSInteger)duration {
|
||||||
NSString *newTime;
|
NSString *newTime;
|
||||||
if (duration < 10) {
|
if (duration < 10) {
|
||||||
|
|||||||
@@ -3,9 +3,10 @@
|
|||||||
"Back"="Zurück";
|
"Back"="Zurück";
|
||||||
"All"="Alle Fotos";
|
"All"="Alle Fotos";
|
||||||
"Video"="Video";
|
"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";
|
"ok"="OK";
|
||||||
"Unable to access album" = "Auf Album kann nicht zugegriffen werden";
|
"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\"";
|
"Please allow to access your album" = "Bitte erlaube den Zugriff auf Dein Album in \"Einstellungen -> Datenschutz -> Fotos\"";
|
||||||
"Setting" = "Einstellungen";
|
"Setting" = "Einstellungen";
|
||||||
"Preview" = "Vorschau";
|
"Preview" = "Vorschau";
|
||||||
|
|||||||
@@ -2,8 +2,9 @@
|
|||||||
"Done"="Done";
|
"Done"="Done";
|
||||||
"All"="All photos";
|
"All"="All photos";
|
||||||
"Video"="Video";
|
"Video"="Video";
|
||||||
"maxSelectAlert"="Has reached the maximum number of choices";
|
|
||||||
"ok"="OK";
|
"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";
|
"Unable to access album" = "Unable to access album";
|
||||||
"Please allow to access your album" = "Please allow to access your album in \"Settings -> Privacy -> Album\"";
|
"Please allow to access your album" = "Please allow to access your album in \"Settings -> Privacy -> Album\"";
|
||||||
"Setting" = "Setting";
|
"Setting" = "Setting";
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
"Done"="hecho";
|
"Done"="hecho";
|
||||||
"All"="Todas las fotos";
|
"All"="Todas las fotos";
|
||||||
"Video"="Video";
|
"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";
|
"ok"="OK";
|
||||||
"Unable to access album" = "Denegado el acceso al album";
|
"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\"";
|
"Please allow to access your album" = "Por favor permita el acceso a sus albums en \"Configuraciones -> Privacidad -> Album\"";
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
"Done"="Pronto";
|
"Done"="Pronto";
|
||||||
"All"="Todas as fotos";
|
"All"="Todas as fotos";
|
||||||
"Video"="Vídeo";
|
"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";
|
"ok"="OK";
|
||||||
"Unable to access album" = "Impossibilitado de acessar o álbum";
|
"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\"";
|
"Please allow to access your album" = "Por favor permita acessar o seu álbum em \“Configurações -> Privacidade -> Álbum\"";
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
"Done"="Pronto";
|
"Done"="Pronto";
|
||||||
"All"="Todas as fotos";
|
"All"="Todas as fotos";
|
||||||
"Video"="Vídeo";
|
"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";
|
"ok"="OK";
|
||||||
"Unable to access album" = "Impossibilitado de acessar o álbum";
|
"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\"";
|
"Please allow to access your album" = "Por favor permita acessar o seu álbum em \“Configurações -> Privacidade -> Álbum\"";
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
"Done"="Bitti";
|
"Done"="Bitti";
|
||||||
"All"="Tümü";
|
"All"="Tümü";
|
||||||
"Video"="Video";
|
"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";
|
"ok"="Tamam";
|
||||||
"Unable to access album" = "Galerinize erişilemiyor";
|
"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.";
|
"Please allow to access your album" = "Lütfen \"Ayarlar -> Gizlilik -> Fotoğraflar\" menüsünden uygulamaya erişim izni verin.";
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
"Done"="完成";
|
"Done"="完成";
|
||||||
"All"="所有照片";
|
"All"="所有照片";
|
||||||
"Video"="视频";
|
"Video"="视频";
|
||||||
"maxSelectAlert"="已达到选择数量上限";
|
"maxSelectAlert"="您只能选择%d张图片";
|
||||||
|
"maxSizeAlert"="您只能选择最大%.02f mb的图像";
|
||||||
"ok"="好";
|
"ok"="好";
|
||||||
"Unable to access album" = "无法访问相册";
|
"Unable to access album" = "无法访问相册";
|
||||||
"Please allow to access your album" = "请在设置-隐私-相册中允许访问相册";
|
"Please allow to access your album" = "请在设置-隐私-相册中允许访问相册";
|
||||||
|
|||||||
@@ -30,6 +30,11 @@
|
|||||||
}@catch (NSException *exception) {
|
}@catch (NSException *exception) {
|
||||||
NSLog(@"Exception: %@", exception);
|
NSLog(@"Exception: %@", exception);
|
||||||
}
|
}
|
||||||
|
@try{
|
||||||
|
dmc.maxSelectSize=[[options objectForKey:@"maxSelectSize"]integerValue];
|
||||||
|
}@catch (NSException *exception) {
|
||||||
|
NSLog(@"Exception: %@", exception);
|
||||||
|
}
|
||||||
dmc._delegate=self;
|
dmc._delegate=self;
|
||||||
[self.viewController presentViewController:[[UINavigationController alloc]initWithRootViewController:dmc] animated:YES completion:nil];
|
[self.viewController presentViewController:[[UINavigationController alloc]initWithRootViewController:dmc] animated:YES completion:nil];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user