diff --git a/Classes_cocos/JcWallet.mm b/Classes_cocos/JcWallet.mm index 4cbdb1f..744a769 100644 --- a/Classes_cocos/JcWallet.mm +++ b/Classes_cocos/JcWallet.mm @@ -224,14 +224,18 @@ SE_BIND_FUNC(jsb_wallet_callback) bool jsb_scanQRCode(se::State& s) { const auto& args = s.args(); size_t argc = args.size(); - if (argc >= 1) { + if (argc >= 2) { bool ok; + std::string funid; + ok = seval_to_std_string(args[0], &funid); + SE_PRECONDITION2(ok, false, "Error processing arguments"); std::string title; - ok = seval_to_std_string(args[0], &title); + ok = seval_to_std_string(args[1], &title); SE_PRECONDITION2(ok, false, "Error processing arguments"); NSString *ntitle = [NSString stringWithCString:title.c_str() encoding:NSUTF8StringEncoding]; + NSString *nfunid = [NSString stringWithCString:funid.c_str() encoding:NSUTF8StringEncoding]; UIWindow* window = [[[UIApplication sharedApplication] delegate] window]; - [window.rootViewController scanQRCode:ntitle]; + [window.rootViewController scanQRCode:nfunid title:ntitle]; return true; } return false; diff --git a/Classes_cocos/UIViewController+Wallet.h b/Classes_cocos/UIViewController+Wallet.h index 7f2026d..002a763 100644 --- a/Classes_cocos/UIViewController+Wallet.h +++ b/Classes_cocos/UIViewController+Wallet.h @@ -13,6 +13,6 @@ @interface UIViewController (Wallet) +(void)toWallet:(NSString *)url; --(void)scanQRCode:(NSString *)title; +-(void)scanQRCode:(NSString *)funid title:(NSString *) title; @end diff --git a/Classes_cocos/UIViewController+Wallet.mm b/Classes_cocos/UIViewController+Wallet.mm index 961ada3..8a7252e 100644 --- a/Classes_cocos/UIViewController+Wallet.mm +++ b/Classes_cocos/UIViewController+Wallet.mm @@ -9,6 +9,9 @@ #import "QRCodeReaderViewController.h" #import "QRCodeReader.h" #import "QRCodeReaderDelegate.h" +#include +#include "WalletEvent.h" + @implementation UIViewController (Wallet) @@ -18,8 +21,9 @@ [app openURL:[NSURL URLWithString:url]]; } --(void)scanQRCode:(NSString *)title{ - NSLog(@"scanQRCode: %@", title); +-(void)scanQRCode:(NSString *)funid title:(NSString *) title{ + NSLog(@"scanQRCode:: funId: %@ title: %@", funid, title); + std::string sfunid = std::string([funid UTF8String], [funid lengthOfBytesUsingEncoding:NSUTF8StringEncoding]); if ([QRCodeReader supportsMetadataObjectTypes:@[AVMetadataObjectTypeQRCode]]) { static QRCodeReaderViewController *vc = nil; static dispatch_once_t onceToken; @@ -35,15 +39,48 @@ [vc setCompletionWithBlock:^(NSString *resultAsString) { NSLog(@"Completion with result: %@", resultAsString); [self dismissViewControllerAnimated:YES completion:^{ - }]; + + NSString *result; + if (resultAsString.length > 0) { + result = [NSString stringWithFormat:@"{errcode: 0, data: '%@'}", resultAsString]; + } else { + result = [NSString stringWithFormat:@"{errcode: 1, errmsg: 'cancel'}"]; + } + std::string sresult = std::string([result UTF8String], [result lengthOfBytesUsingEncoding:NSUTF8StringEncoding]); + WalletEvent::Emit(sfunid.c_str(), sresult.c_str()); + }]; }]; [self presentViewController:vc animated:YES completion:NULL]; }); } else { - UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Reader not supported by the current device" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; - - [alert show]; + dispatch_async(dispatch_get_main_queue(), ^{ + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Error" + message:@"The camera is need to scan QR codes" + preferredStyle:UIAlertControllerStyleAlert]; + //We add buttons to the alert controller by creating UIAlertActions: + UIAlertAction *actionOk = [UIAlertAction actionWithTitle:@"Cancel" + style:UIAlertActionStyleCancel + handler: ^(UIAlertAction *action){ + NSLog(@"alert cancel pressed"); + }]; //You can use a block here to handle a press on this button + // + UIAlertAction *setting = [UIAlertAction actionWithTitle:@"Setting" + style:UIAlertActionStyleDefault + handler: ^(UIAlertAction *action){ + NSLog(@"setting pressed"); + NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; + if ([[UIApplication sharedApplication] canOpenURL:url]){ + [[UIApplication sharedApplication] openURL:url]; + } + }]; + [alertController addAction:actionOk]; + [alertController addAction:setting]; + [self presentViewController:alertController animated:YES completion:nil]; + }); + + std::string sresult = "{errcode: 1, errmsg: 'no camera permission'}"; + WalletEvent::Emit(sfunid.c_str(), sresult.c_str()); } } diff --git a/Unity-iPhone.xcodeproj/project.xcworkspace/xcuserdata/zhl.xcuserdatad/UserInterfaceState.xcuserstate b/Unity-iPhone.xcodeproj/project.xcworkspace/xcuserdata/zhl.xcuserdatad/UserInterfaceState.xcuserstate index be38883..62036aa 100644 Binary files a/Unity-iPhone.xcodeproj/project.xcworkspace/xcuserdata/zhl.xcuserdatad/UserInterfaceState.xcuserstate and b/Unity-iPhone.xcodeproj/project.xcworkspace/xcuserdata/zhl.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Unity-iPhone.xcodeproj/xcuserdata/zhl.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Unity-iPhone.xcodeproj/xcuserdata/zhl.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index d70068c..518994f 100644 --- a/Unity-iPhone.xcodeproj/xcuserdata/zhl.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/Unity-iPhone.xcodeproj/xcuserdata/zhl.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -3,262 +3,4 @@ uuid = "B7D09DA6-0F18-414A-A80E-A05383BA2B01" type = "1" version = "2.0"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/js/main.js b/js/main.js index e1e8853..9a336e0 100644 --- a/js/main.js +++ b/js/main.js @@ -234,8 +234,7 @@ function restoreFromMnemonic(funId, mnemonic, password) { function scanQRCode(funId, title) { try { - jsb.scanQRCode(title); - return JSON.stringify({errcode: 0}); + jsb.scanQRCode(funId, title); } catch(err) { return JSON.stringify({errcode: 1, errmsg: err}); }