优化扫码功能

This commit is contained in:
cebgcontract 2022-12-07 10:26:25 +08:00
parent 78a9a1ac38
commit 18ad6ace51
5 changed files with 24 additions and 117 deletions

View File

@ -293,8 +293,8 @@ bool jsb_scanQRCode(se::State& s) {
NSString *nfunid = [NSString stringWithCString:funid.c_str() encoding:NSUTF8StringEncoding];
dispatch_async(dispatch_get_main_queue(), ^{
UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
// [window.rootViewController scanQRCode:nfunid title:ntitle];
[window.rootViewController loadRestoreKey:nfunid oid: ntitle];
[window.rootViewController scanQRCode:nfunid title:ntitle];
// [window.rootViewController loadRestoreKey:nfunid oid: ntitle];
});
return true;
}

View File

@ -342,6 +342,7 @@
if (_delegate && [_delegate respondsToSelector:@selector(readerDidCancel:)]) {
[_delegate readerDidCancel:self];
}
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)switchCameraAction:(UIButton *)button
@ -415,6 +416,9 @@
if (self.completion) {
self.completion(scanResult.strScanned, nil);
}
if (self.delegate && [self.delegate respondsToSelector:@selector(reader:didScanResult:)]) {
[self.delegate reader:self didScanResult:scanResult.strScanned];
}
[self dismissViewControllerAnimated:YES completion:nil];
}

View File

@ -11,14 +11,12 @@
#import "QRCodeReaderDelegate.h"
#import "LBXPermission.h"
#import "LBXPermissionSetting.h"
#include "LBXScanNative.h"
#include "LBXScanTypes.h"
#include "QrCodeViewController.h"
#include <string>
#import "NSString+Customer.h"
#include "JcWallet.h"
@interface UIViewController (QR)<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@interface UIViewController (QR)
@end
static QRCodeReaderViewController *qrcodeReaderVC = nil;
@ -47,31 +45,23 @@ static QRCodeReaderViewController *qrcodeReaderVC = nil;
-(void)loadRestoreKey:(NSString *)funid oid:(NSString *) oid{
NSLog(@"loadRestoreKey::funid: %@, oid:%@", funid, oid);
dispatch_async(dispatch_get_main_queue(), ^{
// UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Tips"
// message:@"In order to restore recovery key, please Scan QRCode or Pick from Photo Library."
// preferredStyle:UIAlertControllerStyleActionSheet];
// UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"Cancel"
// style:UIAlertActionStyleCancel
// handler: ^(UIAlertAction *action){
// [self nativeCb:funid hasErr:YES dataStr: @"user cancel"];
// }];
//
// UIAlertAction *scanAction = [UIAlertAction actionWithTitle:@"Scan"
// style:UIAlertActionStyleDefault
// handler: ^(UIAlertAction *action){
// [self scanQRCode:funid title: @"" restore:YES ];
// }];
//
// UIAlertAction *photoAction = [UIAlertAction actionWithTitle:@"Photo"
// style:UIAlertActionStyleDefault
// handler: ^(UIAlertAction *action){
// [self openLocalPhotoAlbum: funid];
// }];
// [alertController addAction:actionCancel];
// [alertController addAction:scanAction];
// [alertController addAction:photoAction];
// [self presentViewController:alertController animated:YES completion:nil];
[self scanQRCode:funid title: @"" restore:YES ];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Tips"
message:@"In order to restore recovery key, please Scan QRCode or Pick from Photo Library."
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler: ^(UIAlertAction *action){
[self nativeCb:funid hasErr:YES dataStr: @"user cancel"];
}];
UIAlertAction *scanAction = [UIAlertAction actionWithTitle:@"Scan"
style:UIAlertActionStyleDefault
handler: ^(UIAlertAction *action){
[self scanQRCode:funid title: @"" restore:YES ];
}];
[alertController addAction:actionCancel];
[alertController addAction:scanAction];
[self presentViewController:alertController animated:YES completion:nil];
});
}
@ -125,77 +115,6 @@ static QRCodeReaderViewController *qrcodeReaderVC = nil;
}];
}
#pragma mark- - PhotoAlbum
- (void)openLocalPhotoAlbum:(NSString *)funid {
__weak __typeof(self) weakSelf = self;
[LBXPermission authorizeWithType:LBXPermissionType_Photos completion:^(BOOL granted, BOOL firstTime) {
if (granted) {
[weakSelf openLocalPhoto:funid];
} else if (!firstTime ) {
[LBXPermissionSetting showAlertToDislayPrivacySettingWithTitle:@"Error" msg:@"The Photo Library is need to restore recovery key." cancel:@"Cancel" setting:@"Setting" completion:^{
[weakSelf loadRestoreKey:funid oid:@""];
}];
}
}];
}
/*!
* open local Photo Library
*/
- (void)openLocalPhoto:(NSString *)funid {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
// crash on some mobile
picker.allowsEditing = NO;
picker.title = funid;
[self presentViewController:picker animated:YES completion:nil];
}
#pragma mark- - UIImagePickerControllerDelegate
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
[picker dismissViewControllerAnimated:YES completion:^{
NSString *funid = picker.title;
[self handPhotoDidFinishPickingMediaWithInfo:funid info:info];
}];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController*)picker {
[picker dismissViewControllerAnimated:YES completion:^{
NSLog(@"imagePickerControllerDidCancel %@", picker.title);
[self loadRestoreKey: picker.title oid: @"" ];
}];
}
- (void)handPhotoDidFinishPickingMediaWithInfo:(NSString *)funid info:(NSDictionary *)info {
__block UIImage* image = [info objectForKey:UIImagePickerControllerEditedImage];
if (!image){
image = [info objectForKey:UIImagePickerControllerOriginalImage];
}
if (@available(iOS 8.0, *)) {
__weak __typeof(self) weakSelf = self;
[LBXScanNative recognizeImage:image success:^(NSArray<LBXScanResult *> *array) {
[weakSelf scanResultWithArray:funid array:array];
}];
}else{
[self nativeCb:funid hasErr:YES dataStr: @"os version is lower then IOS8.0"];
}
}
- (void)scanResultWithArray:(NSString *)funid array:(NSArray<LBXScanResult*>*)array {
if (!array || array.count < 1) {
[self nativeCb:funid hasErr:YES dataStr: @"error scan photo"];
return;
}
if (!array[0].strScanned || [array[0].strScanned isEqualToString:@""] ) {
[self nativeCb:funid hasErr:YES dataStr: @"failed decoding QR code"];
return;
}
LBXScanResult *scanResult = array[0];
[self nativeCb:funid hasErr:NO dataStr: scanResult.strScanned];
}
-(void)nativeCb:(NSString *)funid hasErr: (BOOL) hasErr dataStr:(NSString *) dataStr {
if ([NSString isStringEmpty:funid]) {
NSLog(@"nativeCallBack with empty funid: %@", funid);

View File

@ -196,22 +196,6 @@
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "B244721D-1CF8-4F01-BE11-03431BBC8C90"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Classes_cocos/UIViewController+QR.mm"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "133"
endingLineNumber = "133"
landmarkName = "-openLocalPhotoAlbum:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent