ソースを参照

IPU标准版:整理拍照、视频类插件

liufl5 3 年 前
コミット
5c242cbc2b

+ 18 - 24
IPUMobileFunc/IPUMobileFunc/Camera/IPUCameraPlugin.h

@ -12,32 +12,26 @@
12 12
13 13
@interface IPUCameraPlugin : IPUPlugin <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
14 14
15
- (void)takePicture:(NSArray *)param;
16
17
- (void)recordVideo:(NSArray *)param;
18
19
- (void)playVideo:(NSArray *)param;
20
15
#pragma mark - 系统相机拍照、选择图库照片
16
/**
17
 调用手机的照相功能,返回相片的路径或相片的Base64编码
18
 JS调用插件名:getPhoto
19
 */
21 20
- (void)getPhotoViaCamera:(NSArray *)param;
22
21
/**
22
 调用手机自带的图库类应用,选择一张相片后返回路径或Base64编码
23
 JS调用插件名:getPicture
24
 */
23 25
- (void)getPhotoViaPhotoLibrary:(NSArray *)param;
24 26
25
- (void)getPhotoViaPhotosAlbum:(NSArray *)param;
26
27
- (void)getBase64Picture:(NSArray *)param;
28
29
/// 拍照获取包含二维码的照片
30
/// @param param 压缩参数,可选,不传则返回图片路径以及不对图片进行压缩
31
/// {"base64" : "返回图片形式,0:图片路径, 1: base64", "length" : "照片大小,单位B,如400 * 1024", "width" : "照片最小宽度,如300"}
32
/// callback: {"result" : "图片base64编码或者路径", "qrcodes" : ["图片中所含二维码检测结果,如无二维码则为空字符串"]}
33
- (void)getQrCodePhotoViaCamera:(NSArray *)param;
34
35
/// 通过相册获取包含二维码的照片
36
/// @param param 压缩参数,可选,不传则返回图片路径以及不对图片进行压缩
37
/// {"base64" : "返回图片形式,0:图片路径, 1: base64", "length" : "照片大小,单位B,如400 * 1024", "width" : "照片最小宽度,如300"}
38
/// callback: {"result" : "图片base64编码或者路径", "qrcodes" : ["图片中所含二维码检测结果,如无二维码则为空字符串"]}
39
- (void)getQrCodePhotoViaLibrary:(NSArray *)param;
40
41
- (NSString *)base64Encoding:(NSString *)filePath;
27
#pragma mark - 系统相机视频录制、视频播放
28
/**
29
 视频录制
30
 */
31
- (void)recordVideo:(NSArray *)param;
32
/**
33
 视频播放
34
*/
35
- (void)playVideo:(NSArray *)param;
42 36
43 37
@end

+ 228 - 230
IPUMobileFunc/IPUMobileFunc/Camera/IPUCameraPlugin.m

@ -17,8 +17,15 @@
17 17
#import <CoreImage/CoreImage.h>
18 18
#import <AVKit/AVKit.h>
19 19
20
// document下图片缓存目录
21
NSString* imageTmp = @"images";
22
20 23
@interface IPUCameraPlugin ()
21 24
{
25
    UIPopoverController *popover;
26
    
27
    BOOL base64;
28
    
22 29
    NSURL *videoPath;
23 30
    
24 31
    CGFloat maxLength;
@ -31,84 +38,150 @@
31 38
32 39
@implementation IPUCameraPlugin
33 40
34
#pragma mark take Picture
41
#pragma mark - 系统相机拍照、选择图库照片
42
/**
43
调用手机的照相功能,返回相片的路径或相片的Base64编码
44
JS调用插件名:getPhoto
45
*/
46
- (void)getPhotoViaCamera:(NSArray *)param {
47
    base64 = NO;    // 默认使用图片路径
48
    self.detectQrcode = NO;
49
    if ([param count] &&
50
        ![param[0] isKindOfClass:[NSNull class]] &&
51
        ![param[0] boolValue]) {
52
        base64 = YES;
53
    }
54
    if (param.count > 1 && ![param[1] isKindOfClass:[NSNull class]]) {
55
        maxLength = [param[1] floatValue];
56
    }
57
    if (param.count > 2 && ![param[2] isKindOfClass:[NSNull class]]) {
58
        minWidth = [param[2] floatValue];
59
    }
60
    
61
    [self doAction:UIImagePickerControllerSourceTypeCamera];
62
}
35 63
36
//compression is 0(most)..1(least)
37
- (void)takePicture:(NSArray *)param {
38
    CGFloat compression = 0.01f;
39
    if (param) {
40
        compression = param.count > 0 ? [NSString stringWithFormat:@"%@",param[0]].floatValue : compression;
64
/**
65
调用手机自带的图库类应用,选择一张相片后返回路径或Base64编码
66
JS调用插件名:getPicture
67
*/
68
- (void)getPhotoViaPhotoLibrary:(NSArray *)param {
69
    base64 = NO;    // 默认使用图片路径
70
    self.detectQrcode = NO;
71
    if ([param count] &&
72
        ![param[0] isKindOfClass:[NSNull class]] &&
73
        ![param[0] boolValue]) {
74
        base64 = YES;
41 75
    }
42
    IPUActionSheetController *sheet;
43
    __weak typeof(self) weakSelf = self;
44
    if ([IPUImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
45
        sheet = [IPUActionSheetController alertWithTitle:nil
46
                                                callback:^(IPUActionSheetController *actionSheet, BOOL isCancel, NSInteger buttonIndex) {
47
            if (isCancel) {
48
                [actionSheet dismissViewControllerAnimated:YES completion:nil];
49
                return ;
50
            }
51
            
52
            NSInteger sourceType = buttonIndex ? UIImagePickerControllerSourceTypePhotoLibrary : UIImagePickerControllerSourceTypeCamera;
53
            __strong typeof(self) strongSelf = weakSelf;
54
            [strongSelf takePicktureWith:sourceType quality:compression];
55
        }
56
                                       cancelButtonTitle:@"取消"
57
                                  destructiveButtonTitle:nil
58
                                       otherButtonTitles:@"拍摄", @"从相册选择", nil];
59
    } else {
60
        sheet = [IPUActionSheetController alertWithTitle:nil
61
                                                callback:^(IPUActionSheetController *actionSheet, BOOL isCancel, NSInteger buttonIndex) {
62
            if (isCancel) {
63
                [actionSheet dismissViewControllerAnimated:YES completion:nil];
64
                return ;
65
            }
66
            
67
            __strong typeof(self) strongSelf = weakSelf;
68
            [strongSelf takePicktureWith:UIImagePickerControllerSourceTypePhotoLibrary quality:compression];
69
        }
70
                                       cancelButtonTitle:@"取消"
71
                                  destructiveButtonTitle:nil
72
                                       otherButtonTitles:@"从相册选择", nil];
76
    if (param.count > 1 && ![param[1] isKindOfClass:[NSNull class]]) {
77
        maxLength = [param[1] floatValue];
73 78
    }
74
    [[self getViewController] presentViewController:sheet animated:YES completion:nil];
79
    if (param.count > 2 && ![param[2] isKindOfClass:[NSNull class]]) {
80
        minWidth = [param[2] floatValue];
81
    }
82
    
83
    [self doAction:UIImagePickerControllerSourceTypePhotoLibrary];
75 84
}
76 85
77
- (void)takePicktureWith:(NSInteger)sourceType quality:(CGFloat)compressionQuality {
86
//获取图片
87
- (void)doAction:(UIImagePickerControllerSourceType)sourceType {
78 88
    __weak typeof(self) weakSelf = self;
79
    IPUImagePickerController *imagePickerVC = [[IPUImagePickerController alloc] initWithBlock:^(IPUImagePickerController *picker, NSDictionary *info) {
89
    IPUImagePickerController *imagePicker = [[IPUImagePickerController alloc] initWithBlock:^(IPUImagePickerController *picker, NSDictionary *info) {
80 90
        __strong typeof(self) strongSelf = weakSelf;
81
        UIImage *selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
91
        UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
92
        
93
        // 拍摄
82 94
        if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
83
            NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
84
            if ([mediaType isEqualToString:@"public.image"] && selectedImage) {
85
                UIImageWriteToSavedPhotosAlbum(selectedImage, strongSelf,  nil, nil);
86
            }
95
            UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);   // 保存图片到相册
87 96
        }
97
        
88 98
        // 压缩图片
89
        NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
90
        NSString *ourDocumentPath =[documentPaths objectAtIndex:0];
99
        NSData *data = [UIImage compressImage:image
100
                                    maxLength:maxLength
101
                                      minWith:minWidth];
102
        if (!data || !data.length) {
103
            [strongSelf error:@"获取图片失败"];
104
            return;
105
        }
91 106
        
92
        NSDateFormatter *formater = [[NSDateFormatter alloc] init];
93
        [formater setDateFormat:@"yyyy-MM-dd-HH:mm:ss"];
94
        NSString *fileName = [ourDocumentPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", [formater stringFromDate:[NSDate date]]]];
95
        NSData *imageData = UIImageJPEGRepresentation(selectedImage,compressionQuality);
96
        [imageData writeToFile:fileName atomically:NO];
107
        NSString *result = nil;
108
        if (!base64) {
109
            NSString *path = [IPUUtility createDirInDocument:imageTmp
110
                                                withFileName:nil
111
                                           withPathExtension:@"jpg"];
112
            [data writeToFile:path atomically:YES];
113
            result = path;
114
        } else {
115
            result = [data base64EncodedStringWithOptions:0];
116
        }
97 117
        
98
        [strongSelf callback:fileName];
118
        if (strongSelf.detectQrcode) {
119
            // 将图片UIImage转为CIImage
120
            CIImage *detectImage = [CIImage imageWithData:UIImagePNGRepresentation(image)];
121
            // 初始化识别类
122
            CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode
123
                                                      context:nil
124
                                                      options:@{CIDetectorAccuracy : CIDetectorAccuracyHigh}];
125
            // 执行识别方法,得到识别结果
126
            NSArray <CIFeature *>*features = [detector featuresInImage:detectImage options:nil];
127
            __block NSMutableArray *detetorResults = [NSMutableArray arrayWithCapacity:features.count];
128
            if (features && features.count) {
129
                [features enumerateObjectsUsingBlock:^(CIFeature * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
130
                    if ([obj.type isEqualToString:CIFeatureTypeQRCode]) {
131
                        CIQRCodeFeature *feature = (CIQRCodeFeature *)obj;
132
                        if ([IPUStringUtility isValiteString:feature.messageString]) {
133
                            [detetorResults addObject:feature.messageString];
134
                        }
135
                    }
136
                }];
137
            }
138
            NSDictionary *dict = @{
139
                @"result"  : result,
140
                @"qrcodes" : [NSArray arrayWithArray:detetorResults]
141
            };
142
            result = [IPUJSONHelper toJSONString:dict];
143
        }
144
        
145
        [strongSelf callback:result];
146
        [strongSelf resetParams];
147
        [picker dismissViewControllerAnimated:YES completion:nil];
99 148
    }];
100
    
101
    imagePickerVC.sourceType = sourceType;
102
    imagePickerVC.allowsEditing = YES;
103
    imagePickerVC.navigationBar.translucent = NO;
104
    
105
    [[self getViewController] presentViewController:imagePickerVC
106
                                           animated:NO
107
                                         completion:nil];
149
    imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;
150
    if ([UIImagePickerController isSourceTypeAvailable:sourceType]) {
151
        imagePicker.sourceType = sourceType;
152
    } else {
153
        UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"照片获取失败"
154
                                                     message:@"没有可用的照片来源"
155
                                                    delegate:nil
156
                                           cancelButtonTitle:@"确定"
157
                                           otherButtonTitles:nil, nil];
158
        [av show];
159
        return;
160
    }
161
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
162
        popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
163
        UIView *view = (UIView *)[self.mobileDelegate getCurrentView];
164
        CGRect rect = CGRectMake(view.bounds.size.width / 2, view.bounds.size.height / 3, 10, 10);
165
        [popover presentPopoverFromRect:rect
166
                                 inView:view
167
               permittedArrowDirections:UIPopoverArrowDirectionAny
168
                               animated:YES];
169
    } else {
170
        [[self getViewController] presentViewController:imagePicker animated: YES completion: nil];
171
    }
108 172
}
109 173
110
#pragma mark record Vedio
174
- (void)resetParams {
175
    base64 = NO;
176
    self.detectQrcode = NO;
177
    CGFloat maxLength = 0.0;
178
    CGFloat minWidth = 0.0;
179
}
111 180
181
#pragma mark - 系统相机视频录制、视频播放
182
/**
183
 视频录制
184
 */
112 185
- (void)recordVideo:(NSArray *)param {
113 186
    double compressRatio = 1.0f, timeLimit = 30.0f;
114 187
    @try {
@ -157,7 +230,6 @@
157 230
        [[self getViewController] presentViewController:ipc animated:NO completion:nil];
158 231
    }
159 232
}
160
161 233
// 压缩
162 234
- (void)convert {
163 235
    if (!videoPath) {
@ -195,13 +267,9 @@
195 267
    }
196 268
}
197 269
198
/*************************************************
199
 * 播放制定视频文件
200
 * param(param) 数组,包含播放文件路径
270
/**
271
 视频播放
201 272
 */
202
203
#pragma mark playVideo
204
205 273
- (void)playVideo:(NSArray *)param {
206 274
    NSString *path = param[0];
207 275
    
@ -223,68 +291,42 @@
223 291
    [self callback:@""];
224 292
}
225 293
226
#pragma mark 暂时不需要
227 294
228
- (void)loadVideoImage{
229
    if (videoPath) {
230
        AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoPath options:nil];
231
        AVAssetImageGenerator *gen = [[AVAssetImageGenerator alloc] initWithAsset:asset];
232
        gen.appliesPreferredTrackTransform = YES;
233
        CMTime time = CMTimeMakeWithSeconds(0.1, 600); // 参数( 截取的秒数, 视频每秒多少帧)
234
        NSError *error = nil;
235
        CMTime actualTime;
236
        CGImageRef image = [gen copyCGImageAtTime:time actualTime:&actualTime error:&error];
237
        //        UIImage *thumb = [[UIImage alloc] initWithCGImage:image];
238
        CGImageRelease(image);
239
    }
295
#pragma mark - 二维码相关
296
/// 拍照获取包含二维码的照片
297
/// @param param 压缩参数,可选,不传则返回图片路径以及不对图片进行压缩
298
/// {"base64" : "返回图片形式,0:图片路径, 1: base64", "length" : "照片大小,单位B,如400 * 1024", "width" : "照片最小宽度,如300"}
299
/// callback: {"result" : "图片base64编码或者路径", "qrcodes" : ["图片中所含二维码检测结果,如无二维码则为空字符串"]}
300
- (void)getQrCodePhotoViaCamera:(NSArray *)param {
301
    [self getQrCodePhoto:param type:UIImagePickerControllerSourceTypeCamera];
240 302
}
241 303
242
UIPopoverController *popover;
243
244
// document下图片缓存目录
245
NSString* imageTmp = @"images";
246
247
BOOL base64;
248
249
/* 利用摄像头拍照获取图片 */
250
- (void)getPhotoViaCamera:(NSArray *)param {
251
    base64 = NO;    // 默认使用图片路径
252
    self.detectQrcode = NO;
253
    if ([param count] &&
254
        ![param[0] isKindOfClass:[NSNull class]] &&
255
        ![param[0] boolValue]) {
256
        base64 = YES;
257
    }
258
    if (param.count > 1 && ![param[1] isKindOfClass:[NSNull class]]) {
259
        maxLength = [param[1] floatValue];
260
    }
261
    if (param.count > 2 && ![param[2] isKindOfClass:[NSNull class]]) {
262
        minWidth = [param[2] floatValue];
263
    }
264
    
265
    [self doAction:UIImagePickerControllerSourceTypeCamera];
304
/// 通过相册获取包含二维码的照片
305
/// @param param 压缩参数,可选,不传则返回图片路径以及不对图片进行压缩
306
/// {"base64" : "返回图片形式,0:图片路径, 1: base64", "length" : "照片大小,单位B,如400 * 1024", "width" : "照片最小宽度,如300"}
307
/// callback: {"result" : "图片base64编码或者路径", "qrcodes" : ["图片中所含二维码检测结果,如无二维码则为空字符串"]}
308
- (void)getQrCodePhotoViaLibrary:(NSArray *)param {
309
    [self getQrCodePhoto:param type:UIImagePickerControllerSourceTypePhotoLibrary];
266 310
}
267 311
268
/* 从图库获取图片 */
269
- (void)getPhotoViaPhotoLibrary:(NSArray *)param {
270
    base64 = NO;    // 默认使用图片路径
271
    self.detectQrcode = NO;
272
    if ([param count] &&
273
        ![param[0] isKindOfClass:[NSNull class]] &&
274
        ![param[0] boolValue]) {
275
        base64 = YES;
276
    }
277
    if (param.count > 1 && ![param[1] isKindOfClass:[NSNull class]]) {
278
        maxLength = [param[1] floatValue];
279
    }
280
    if (param.count > 2 && ![param[2] isKindOfClass:[NSNull class]]) {
281
        minWidth = [param[2] floatValue];
312
- (void)getQrCodePhoto:(NSArray *)param type:(UIImagePickerControllerSourceType)sourceType {
313
    @try {
314
        NSDictionary *dict = [IPUJSONHelper toDictionary:param[0]];
315
        base64 = [dict[@"base64"] boolValue];
316
        maxLength = [dict[@"length"] floatValue];
317
        minWidth = [dict[@"width"] floatValue];
318
        self.detectQrcode = YES;
319
    } @catch (NSException *exception) {
320
        
321
    } @finally {
322
        [self doAction:sourceType];
282 323
    }
283
    
284
    [self doAction:UIImagePickerControllerSourceTypePhotoLibrary];
285 324
}
286 325
287
/* 从相册获取图片 */
326
#pragma mark - other
327
/**
328
从相册获取图片
329
*/
288 330
- (void)getPhotoViaPhotosAlbum:(NSArray *)param {
289 331
    base64 = NO;    // 默认使用图片路径
290 332
    self.detectQrcode = NO;
@ -309,28 +351,6 @@ BOOL base64;
309 351
    [self callback:base64];
310 352
}
311 353
312
- (void)getQrCodePhotoViaCamera:(NSArray *)param {
313
    [self getQrCodePhoto:param type:UIImagePickerControllerSourceTypeCamera];
314
}
315
316
- (void)getQrCodePhotoViaLibrary:(NSArray *)param {
317
    [self getQrCodePhoto:param type:UIImagePickerControllerSourceTypePhotoLibrary];
318
}
319
320
- (void)getQrCodePhoto:(NSArray *)param type:(UIImagePickerControllerSourceType)sourceType {
321
    @try {
322
        NSDictionary *dict = [IPUJSONHelper toDictionary:param[0]];
323
        base64 = [dict[@"base64"] boolValue];
324
        maxLength = [dict[@"length"] floatValue];
325
        minWidth = [dict[@"width"] floatValue];
326
        self.detectQrcode = YES;
327
    } @catch (NSException *exception) {
328
        
329
    } @finally {
330
        [self doAction:sourceType];
331
    }
332
}
333
334 354
- (NSString *)base64Encoding:(NSString *)filePath {
335 355
    UIImage *image = [UIImage imageWithContentsOfFile:filePath];
336 356
    if (image) {
@ -342,99 +362,77 @@ BOOL base64;
342 362
    return nil;
343 363
}
344 364
345
/* 获取图片 */
346
- (void)doAction:(UIImagePickerControllerSourceType)sourceType {
365
- (void)takePicture:(NSArray *)param {
366
    CGFloat compression = 0.01f;
367
    if (param) {
368
        compression = param.count > 0 ? [NSString stringWithFormat:@"%@",param[0]].floatValue : compression;
369
    }
370
    IPUActionSheetController *sheet;
347 371
    __weak typeof(self) weakSelf = self;
348
    IPUImagePickerController *imagePicker = [[IPUImagePickerController alloc] initWithBlock:^(IPUImagePickerController *picker, NSDictionary *info) {
372
    if ([IPUImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
373
        sheet = [IPUActionSheetController alertWithTitle:nil
374
                                                callback:^(IPUActionSheetController *actionSheet, BOOL isCancel, NSInteger buttonIndex) {
375
            if (isCancel) {
376
                [actionSheet dismissViewControllerAnimated:YES completion:nil];
377
                return ;
378
            }
379
            
380
            NSInteger sourceType = buttonIndex ? UIImagePickerControllerSourceTypePhotoLibrary : UIImagePickerControllerSourceTypeCamera;
381
            __strong typeof(self) strongSelf = weakSelf;
382
            [strongSelf takePicktureWith:sourceType quality:compression];
383
        }
384
                                       cancelButtonTitle:@"取消"
385
                                  destructiveButtonTitle:nil
386
                                       otherButtonTitles:@"拍摄", @"从相册选择", nil];
387
    } else {
388
        sheet = [IPUActionSheetController alertWithTitle:nil
389
                                                callback:^(IPUActionSheetController *actionSheet, BOOL isCancel, NSInteger buttonIndex) {
390
            if (isCancel) {
391
                [actionSheet dismissViewControllerAnimated:YES completion:nil];
392
                return ;
393
            }
394
            
395
            __strong typeof(self) strongSelf = weakSelf;
396
            [strongSelf takePicktureWith:UIImagePickerControllerSourceTypePhotoLibrary quality:compression];
397
        }
398
                                       cancelButtonTitle:@"取消"
399
                                  destructiveButtonTitle:nil
400
                                       otherButtonTitles:@"从相册选择", nil];
401
    }
402
    [[self getViewController] presentViewController:sheet animated:YES completion:nil];
403
}
404
405
- (void)takePicktureWith:(NSInteger)sourceType quality:(CGFloat)compressionQuality {
406
    __weak typeof(self) weakSelf = self;
407
    IPUImagePickerController *imagePickerVC = [[IPUImagePickerController alloc] initWithBlock:^(IPUImagePickerController *picker, NSDictionary *info) {
349 408
        __strong typeof(self) strongSelf = weakSelf;
350
        UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
351
        
352
        // 拍摄
409
        UIImage *selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
353 410
        if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
354
            UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);   // 保存图片到相册
411
            NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
412
            if ([mediaType isEqualToString:@"public.image"] && selectedImage) {
413
                UIImageWriteToSavedPhotosAlbum(selectedImage, strongSelf,  nil, nil);
414
            }
355 415
        }
356
        
357 416
        // 压缩图片
358
        NSData *data = [UIImage compressImage:image
359
                                    maxLength:maxLength
360
                                      minWith:minWidth];
361
        if (!data || !data.length) {
362
            [strongSelf error:@"获取图片失败"];
363
            return;
364
        }
365
        
366
        NSString *result = nil;
367
        if (!base64) {
368
            NSString *path = [IPUUtility createDirInDocument:imageTmp
369
                                                withFileName:nil
370
                                           withPathExtension:@"jpg"];
371
            [data writeToFile:path atomically:YES];
372
            result = path;
373
        } else {
374
            result = [data base64EncodedStringWithOptions:0];
375
        }
417
        NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
418
        NSString *ourDocumentPath =[documentPaths objectAtIndex:0];
376 419
        
377
        if (strongSelf.detectQrcode) {
378
            // 将图片UIImage转为CIImage
379
            CIImage *detectImage = [CIImage imageWithData:UIImagePNGRepresentation(image)];
380
            // 初始化识别类
381
            CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode
382
                                                      context:nil
383
                                                      options:@{CIDetectorAccuracy : CIDetectorAccuracyHigh}];
384
            // 执行识别方法,得到识别结果
385
            NSArray <CIFeature *>*features = [detector featuresInImage:detectImage options:nil];
386
            __block NSMutableArray *detetorResults = [NSMutableArray arrayWithCapacity:features.count];
387
            if (features && features.count) {
388
                [features enumerateObjectsUsingBlock:^(CIFeature * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
389
                    if ([obj.type isEqualToString:CIFeatureTypeQRCode]) {
390
                        CIQRCodeFeature *feature = (CIQRCodeFeature *)obj;
391
                        if ([IPUStringUtility isValiteString:feature.messageString]) {
392
                            [detetorResults addObject:feature.messageString];
393
                        }
394
                    }
395
                }];
396
            }
397
            NSDictionary *dict = @{
398
                @"result"  : result,
399
                @"qrcodes" : [NSArray arrayWithArray:detetorResults]
400
            };
401
            result = [IPUJSONHelper toJSONString:dict];
402
        }
420
        NSDateFormatter *formater = [[NSDateFormatter alloc] init];
421
        [formater setDateFormat:@"yyyy-MM-dd-HH:mm:ss"];
422
        NSString *fileName = [ourDocumentPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", [formater stringFromDate:[NSDate date]]]];
423
        NSData *imageData = UIImageJPEGRepresentation(selectedImage,compressionQuality);
424
        [imageData writeToFile:fileName atomically:NO];
403 425
        
404
        [strongSelf callback:result];
405
        [strongSelf resetParams];
406
        [picker dismissViewControllerAnimated:YES completion:nil];
426
        [strongSelf callback:fileName];
407 427
    }];
408
    imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;
409
    if ([UIImagePickerController isSourceTypeAvailable:sourceType]) {
410
        imagePicker.sourceType = sourceType;
411
    } else {
412
        UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"照片获取失败"
413
                                                     message:@"没有可用的照片来源"
414
                                                    delegate:nil
415
                                           cancelButtonTitle:@"确定"
416
                                           otherButtonTitles:nil, nil];
417
        [av show];
418
        return;
419
    }
420
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
421
        popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
422
        UIView *view = (UIView *)[self.mobileDelegate getCurrentView];
423
        CGRect rect = CGRectMake(view.bounds.size.width / 2, view.bounds.size.height / 3, 10, 10);
424
        [popover presentPopoverFromRect:rect
425
                                 inView:view
426
               permittedArrowDirections:UIPopoverArrowDirectionAny
427
                               animated:YES];
428
    } else {
429
        [[self getViewController] presentViewController:imagePicker animated: YES completion: nil];
430
    }
431
}
432
433
- (void)resetParams {
434
    base64 = NO;
435
    self.detectQrcode = NO;
436
    CGFloat maxLength = 0.0;
437
    CGFloat minWidth = 0.0;
428
    
429
    imagePickerVC.sourceType = sourceType;
430
    imagePickerVC.allowsEditing = YES;
431
    imagePickerVC.navigationBar.translucent = NO;
432
    
433
    [[self getViewController] presentViewController:imagePickerVC
434
                                           animated:NO
435
                                         completion:nil];
438 436
}
439 437
440 438
@end

+ 4 - 0
IPUMobileFunc/IPUMobileFunc/IPUBasicPlugin.m

@ -61,6 +61,10 @@
61 61
    BOOL re = [self openUrl:[NSString stringWithFormat:@"mailto://%@", address]];
62 62
    return re;
63 63
}
64
- (BOOL)openUrl:(NSString *)url {
65
    BOOL re = [[UIApplication sharedApplication]openURL:[NSURL URLWithString:url]];
66
    return re;
67
}
64 68
65 69
/**
66 70
 响铃

+ 3 - 0
IPUMobileFunc/IPUMobileFunc/IPUVideoRecordPlugin.h

@ -15,6 +15,9 @@
15 15
16 16
@interface IPUVideoRecordPlugin : IPUPlugin
17 17
18
/**
19
 录制短视频
20
 */
18 21
- (void)recordShortVideo:(NSArray *)param;
19 22
20 23
@end

+ 3 - 0
IPUMobileFunc/IPUMobileFunc/IPUVideoRecordPlugin.m

@ -25,6 +25,9 @@
25 25
26 26
@implementation IPUVideoRecordPlugin
27 27
28
/**
29
录制短视频
30
*/
28 31
- (void)recordShortVideo:(NSArray *)param {
29 32
    int seconds = 6;
30 33
    if (param && param.count) {

+ 8 - 7
display-center/Res/config/mobile-action.xml

@ -41,8 +41,14 @@
41 41
    <action name="loadPage"     class="IPUMobileUIPlugin" method="loadPage"/>
42 42
    <action name="loadTemplate" class="IPUMobileUIPlugin" method="loadTemplate"/>
43 43
    
44
    <!--  Camera & Custom Camera -->
44 45
    <action name="getPhoto"         class="IPUCameraPlugin" method="getPhotoViaCamera"/>
45 46
    <action name="getPicture"       class="IPUCameraPlugin" method="getPhotoViaPhotoLibrary"/>
47
    <action name="getIdentifyPhoto" class="IPUCustomCameraPlugin" method="getIdentifyPhoto"/>
48
    <!--  Video & Custom Video -->
49
    <action name="recordVideo" class="IPUCameraPlugin" method="recordVideo"/>
50
    <action name="playVideo"   class="IPUCameraPlugin" method="playVideo"/>
51
    <action name="makeShortVideo" class="IPUVideoRecordPlugin" method="recordShortVideo"/>
46 52
    
47 53
    <action name="getQrCodePhotoViaCamera"  class="IPUCameraPlugin" method="getQrCodePhotoViaCamera"/>
48 54
    <action name="getQrCodePhotoViaLibrary" class="IPUCameraPlugin" method="getQrCodePhotoViaLibrary"/>
@ -107,15 +113,10 @@
107 113
    <action name="getContacts"      class="IPUContactsPlugin" method="getContacts"/>
108 114
    <action name="shareImageBymail" class="IPUMailPlugin"     method="shareImageBymail"/>
109 115
    
110
    <!--  Camera -->
111
    <action name="recordVideo" class="IPUCameraPlugin" method="recordVideo"/>
112
    <action name="playVideo"   class="IPUCameraPlugin" method="playVideo"/>
113
    
114 116
    <action name="getVideoPath"    class="IPUVideoPlugin" method="getVideoPath"/>
115 117
    <action name="videoCompressor" class="IPUVideoPlugin" method="videoCompressor"/>
116 118
    
117
    <!--  Custom Camera -->
118
    <action name="getIdentifyPhoto" class="IPUCustomCameraPlugin" method="getIdentifyPhoto"/>
119
    
119 120
    
120 121
    <!-- Upload File -->
121 122
    <action name="uploadWithServlet"   class="IPUUploadDownloadPlugin" method="uploadWithServletByAFN"/>
@ -214,7 +215,7 @@
214 215
    <action name="delGestureLock"      class="IPUAuthenticationPlugin" method="delGestureLock"/>
215 216
    <action name="isSetGestureLock"    class="IPUAuthenticationPlugin" method="isSetGestureLock"/>
216 217
    
217
    <action name="makeShortVideo" class="IPUVideoRecordPlugin" method="recordShortVideo"/>
218
    
218 219
219 220
    <!-- OCR识别 -->
220 221
    <action name="getFloCardInfoBD" class="IPUOCRPlugin" method="getFloCardInfoBD"/>

BIN
display-center/display-center.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate