From 564b3853854f088d3be5e67e674d60cfb17f7532 Mon Sep 17 00:00:00 2001 From: dmcBig Date: Tue, 15 May 2018 16:34:37 +0800 Subject: [PATCH] ios test --- .../DMCMediaPicker/DmcPickerViewController.m | 1 + src/ios/MediaPicker.m | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/ios/DMCMediaPicker/DmcPickerViewController.m b/src/ios/DMCMediaPicker/DmcPickerViewController.m index f24612c..c772644 100644 --- a/src/ios/DMCMediaPicker/DmcPickerViewController.m +++ b/src/ios/DMCMediaPicker/DmcPickerViewController.m @@ -43,6 +43,7 @@ } -(void) cancel{ + [self._delegate resultPicker:selectArray]; [self dismissViewControllerAnimated:YES completion:nil]; } diff --git a/src/ios/MediaPicker.m b/src/ios/MediaPicker.m index 2abdeb8..5604de8 100644 --- a/src/ios/MediaPicker.m +++ b/src/ios/MediaPicker.m @@ -224,6 +224,45 @@ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:options] callbackId:callbackId]; } +- (void)compressImage:(CDVInvokedUrlCommand*)command +{ + callbackId=command.callbackId; + NSMutableDictionary *options = [command.arguments objectAtIndex: 0]; + + NSInteger quality=[[options objectForKey:@"thumbnailQuality"] integerValue]; + if(quality<100&&[@"image" isEqualToString: [options objectForKey:@"mediaType"]]){ + UIImage *result = [[UIImage alloc] initWithContentsOfFile: [options objectForKey:@"path"]]; + NSInteger qu = quality>0?quality:3; + CGFloat q=qu/100.0f; + NSData *data =UIImageJPEGRepresentation(result,q); + NSString*timeString = [NSString stringWithFormat:@"%0.f", [[NSDate dateWithTimeIntervalSinceNow:0] timeIntervalSince1970]]; + NSString *filename=[NSString stringWithFormat:@"dmcMediaPickerCompress", timeString,@".jpg"]; + NSString *fullpath=[NSString stringWithFormat:@"%@/%@", dmcPickerPath,filename]; + NSUInteger size=data.length; + NSError *error = nil; + if (![data writeToFile:fullpath options:NSAtomicWrite error:&error]) { + NSLog(@"%@", [error localizedDescription]); + [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]] callbackId:callbackId]; + } else { + [options setObject:fullpath forKey:@"path"]; + [options setObject:size forKey:@"size"]; + [options setObject:filename forKey:@"name"]; + [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:options] callbackId:callbackId]; + } + + }else{ + [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:options] callbackId:callbackId]; + } +} + +-(void)fileToBlob:(CDVInvokedUrlCommand*)command +{ + callbackId=command.callbackId; + NSMutableDictionary *options = [command.arguments objectAtIndex: 0]; + UIImage *result =[NSData dataWithContentsOfFile:[options objectForKey:@"path"]]; + [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArrayBuffer:result]callbackId:command.callbackId]; +} + -(int)getOrientation:(UIImage *)image{ switch (image.imageOrientation) { case UIImageOrientationDown: