增加扫码回调
This commit is contained in:
parent
93f273ed81
commit
d260ebe0d2
@ -224,14 +224,18 @@ SE_BIND_FUNC(jsb_wallet_callback)
|
|||||||
bool jsb_scanQRCode(se::State& s) {
|
bool jsb_scanQRCode(se::State& s) {
|
||||||
const auto& args = s.args();
|
const auto& args = s.args();
|
||||||
size_t argc = args.size();
|
size_t argc = args.size();
|
||||||
if (argc >= 1) {
|
if (argc >= 2) {
|
||||||
bool ok;
|
bool ok;
|
||||||
|
std::string funid;
|
||||||
|
ok = seval_to_std_string(args[0], &funid);
|
||||||
|
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||||
std::string title;
|
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");
|
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||||
NSString *ntitle = [NSString stringWithCString:title.c_str() encoding:NSUTF8StringEncoding];
|
NSString *ntitle = [NSString stringWithCString:title.c_str() encoding:NSUTF8StringEncoding];
|
||||||
|
NSString *nfunid = [NSString stringWithCString:funid.c_str() encoding:NSUTF8StringEncoding];
|
||||||
UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
|
UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
|
||||||
[window.rootViewController scanQRCode:ntitle];
|
[window.rootViewController scanQRCode:nfunid title:ntitle];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -13,6 +13,6 @@
|
|||||||
@interface UIViewController (Wallet)
|
@interface UIViewController (Wallet)
|
||||||
|
|
||||||
+(void)toWallet:(NSString *)url;
|
+(void)toWallet:(NSString *)url;
|
||||||
-(void)scanQRCode:(NSString *)title;
|
-(void)scanQRCode:(NSString *)funid title:(NSString *) title;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -9,6 +9,9 @@
|
|||||||
#import "QRCodeReaderViewController.h"
|
#import "QRCodeReaderViewController.h"
|
||||||
#import "QRCodeReader.h"
|
#import "QRCodeReader.h"
|
||||||
#import "QRCodeReaderDelegate.h"
|
#import "QRCodeReaderDelegate.h"
|
||||||
|
#include <string>
|
||||||
|
#include "WalletEvent.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@implementation UIViewController (Wallet)
|
@implementation UIViewController (Wallet)
|
||||||
@ -18,8 +21,9 @@
|
|||||||
[app openURL:[NSURL URLWithString:url]];
|
[app openURL:[NSURL URLWithString:url]];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)scanQRCode:(NSString *)title{
|
-(void)scanQRCode:(NSString *)funid title:(NSString *) title{
|
||||||
NSLog(@"scanQRCode: %@", title);
|
NSLog(@"scanQRCode:: funId: %@ title: %@", funid, title);
|
||||||
|
std::string sfunid = std::string([funid UTF8String], [funid lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
|
||||||
if ([QRCodeReader supportsMetadataObjectTypes:@[AVMetadataObjectTypeQRCode]]) {
|
if ([QRCodeReader supportsMetadataObjectTypes:@[AVMetadataObjectTypeQRCode]]) {
|
||||||
static QRCodeReaderViewController *vc = nil;
|
static QRCodeReaderViewController *vc = nil;
|
||||||
static dispatch_once_t onceToken;
|
static dispatch_once_t onceToken;
|
||||||
@ -35,15 +39,48 @@
|
|||||||
[vc setCompletionWithBlock:^(NSString *resultAsString) {
|
[vc setCompletionWithBlock:^(NSString *resultAsString) {
|
||||||
NSLog(@"Completion with result: %@", resultAsString);
|
NSLog(@"Completion with result: %@", resultAsString);
|
||||||
[self dismissViewControllerAnimated:YES completion:^{
|
[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];
|
[self presentViewController:vc animated:YES completion:NULL];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Reader not supported by the current device" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
|
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];
|
||||||
|
});
|
||||||
|
|
||||||
[alert show];
|
std::string sresult = "{errcode: 1, errmsg: 'no camera permission'}";
|
||||||
|
WalletEvent::Emit(sfunid.c_str(), sresult.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Binary file not shown.
@ -3,262 +3,4 @@
|
|||||||
uuid = "B7D09DA6-0F18-414A-A80E-A05383BA2B01"
|
uuid = "B7D09DA6-0F18-414A-A80E-A05383BA2B01"
|
||||||
type = "1"
|
type = "1"
|
||||||
version = "2.0">
|
version = "2.0">
|
||||||
<Breakpoints>
|
|
||||||
<BreakpointProxy
|
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
|
||||||
<BreakpointContent
|
|
||||||
uuid = "3116743D-0CBB-4D4D-BB44-E08064BF250E"
|
|
||||||
shouldBeEnabled = "No"
|
|
||||||
ignoreCount = "0"
|
|
||||||
continueAfterRunningActions = "No"
|
|
||||||
filePath = "../../../../cocos/cocos2d-x/cocos/scripting/js-bindings/manual/jsb_global.cpp"
|
|
||||||
startingColumnNumber = "9223372036854775807"
|
|
||||||
endingColumnNumber = "9223372036854775807"
|
|
||||||
startingLineNumber = "885"
|
|
||||||
endingLineNumber = "885"
|
|
||||||
landmarkName = "jsb_register_global_variables(global)"
|
|
||||||
landmarkType = "9">
|
|
||||||
</BreakpointContent>
|
|
||||||
</BreakpointProxy>
|
|
||||||
<BreakpointProxy
|
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
|
||||||
<BreakpointContent
|
|
||||||
uuid = "7EC97F82-E49A-4691-A304-6A0B8528ED64"
|
|
||||||
shouldBeEnabled = "No"
|
|
||||||
ignoreCount = "0"
|
|
||||||
continueAfterRunningActions = "No"
|
|
||||||
filePath = "Classes_cocos/JcWallet.cpp"
|
|
||||||
startingColumnNumber = "9223372036854775807"
|
|
||||||
endingColumnNumber = "9223372036854775807"
|
|
||||||
startingLineNumber = "159"
|
|
||||||
endingLineNumber = "159"
|
|
||||||
landmarkName = "tick(dt)"
|
|
||||||
landmarkType = "9">
|
|
||||||
</BreakpointContent>
|
|
||||||
</BreakpointProxy>
|
|
||||||
<BreakpointProxy
|
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
|
||||||
<BreakpointContent
|
|
||||||
uuid = "3B15BB3A-5820-4171-B3E3-ACF515C353DE"
|
|
||||||
shouldBeEnabled = "No"
|
|
||||||
ignoreCount = "0"
|
|
||||||
continueAfterRunningActions = "No"
|
|
||||||
filePath = "Classes_cocos/JcWallet.cpp"
|
|
||||||
startingColumnNumber = "9223372036854775807"
|
|
||||||
endingColumnNumber = "9223372036854775807"
|
|
||||||
startingLineNumber = "121"
|
|
||||||
endingLineNumber = "121"
|
|
||||||
landmarkName = "JcWallet::tick(dt)"
|
|
||||||
landmarkType = "7">
|
|
||||||
</BreakpointContent>
|
|
||||||
</BreakpointProxy>
|
|
||||||
<BreakpointProxy
|
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
|
||||||
<BreakpointContent
|
|
||||||
uuid = "F73D5391-C9FC-465E-BDC5-F37B2F9B83E3"
|
|
||||||
shouldBeEnabled = "No"
|
|
||||||
ignoreCount = "0"
|
|
||||||
continueAfterRunningActions = "No"
|
|
||||||
filePath = "../../../../cocos/cocos2d-x/cocos/base/CCScheduler.cpp"
|
|
||||||
startingColumnNumber = "9223372036854775807"
|
|
||||||
endingColumnNumber = "9223372036854775807"
|
|
||||||
startingLineNumber = "460"
|
|
||||||
endingLineNumber = "460"
|
|
||||||
landmarkName = "Scheduler::update(dt)"
|
|
||||||
landmarkType = "7">
|
|
||||||
</BreakpointContent>
|
|
||||||
</BreakpointProxy>
|
|
||||||
<BreakpointProxy
|
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
|
||||||
<BreakpointContent
|
|
||||||
uuid = "9A9C4B5F-9C59-4E59-8ACA-9D39B4593C20"
|
|
||||||
shouldBeEnabled = "No"
|
|
||||||
ignoreCount = "0"
|
|
||||||
continueAfterRunningActions = "No"
|
|
||||||
filePath = "../../../../cocos/cocos2d-x/cocos/platform/ios/CCApplication-ios.mm"
|
|
||||||
startingColumnNumber = "9223372036854775807"
|
|
||||||
endingColumnNumber = "9223372036854775807"
|
|
||||||
startingLineNumber = "62"
|
|
||||||
endingLineNumber = "62"
|
|
||||||
landmarkName = "-initWithApplication:"
|
|
||||||
landmarkType = "7">
|
|
||||||
</BreakpointContent>
|
|
||||||
</BreakpointProxy>
|
|
||||||
<BreakpointProxy
|
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
|
||||||
<BreakpointContent
|
|
||||||
uuid = "42E93B27-26C3-4DF6-83E1-39E31DA75188"
|
|
||||||
shouldBeEnabled = "No"
|
|
||||||
ignoreCount = "0"
|
|
||||||
continueAfterRunningActions = "No"
|
|
||||||
filePath = "../../../../cocos/cocos2d-x/cocos/platform/ios/CCApplication-ios.mm"
|
|
||||||
startingColumnNumber = "9223372036854775807"
|
|
||||||
endingColumnNumber = "9223372036854775807"
|
|
||||||
startingLineNumber = "178"
|
|
||||||
endingLineNumber = "178"
|
|
||||||
landmarkName = "Application::Application(name, width, height)"
|
|
||||||
landmarkType = "7">
|
|
||||||
</BreakpointContent>
|
|
||||||
</BreakpointProxy>
|
|
||||||
<BreakpointProxy
|
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
|
||||||
<BreakpointContent
|
|
||||||
uuid = "ADB8CDF0-B654-4692-8623-5AC0613B9154"
|
|
||||||
shouldBeEnabled = "No"
|
|
||||||
ignoreCount = "0"
|
|
||||||
continueAfterRunningActions = "No"
|
|
||||||
filePath = "Classes/UnityAppController.mm"
|
|
||||||
startingColumnNumber = "9223372036854775807"
|
|
||||||
endingColumnNumber = "9223372036854775807"
|
|
||||||
startingLineNumber = "404"
|
|
||||||
endingLineNumber = "404"
|
|
||||||
landmarkName = "-applicationWillResignActive:"
|
|
||||||
landmarkType = "7">
|
|
||||||
</BreakpointContent>
|
|
||||||
</BreakpointProxy>
|
|
||||||
<BreakpointProxy
|
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
|
||||||
<BreakpointContent
|
|
||||||
uuid = "A3DC55C3-1CB9-4E63-9F4F-6BF10B9C9F0E"
|
|
||||||
shouldBeEnabled = "No"
|
|
||||||
ignoreCount = "0"
|
|
||||||
continueAfterRunningActions = "No"
|
|
||||||
filePath = "Classes/UnityAppController.mm"
|
|
||||||
startingColumnNumber = "9223372036854775807"
|
|
||||||
endingColumnNumber = "9223372036854775807"
|
|
||||||
startingLineNumber = "399"
|
|
||||||
endingLineNumber = "399"
|
|
||||||
landmarkName = "-applicationWillResignActive:"
|
|
||||||
landmarkType = "7">
|
|
||||||
</BreakpointContent>
|
|
||||||
</BreakpointProxy>
|
|
||||||
<BreakpointProxy
|
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
|
||||||
<BreakpointContent
|
|
||||||
uuid = "E9A3C254-BEF5-44F3-82B9-B0303174F92F"
|
|
||||||
shouldBeEnabled = "No"
|
|
||||||
ignoreCount = "0"
|
|
||||||
continueAfterRunningActions = "No"
|
|
||||||
filePath = "Classes_cocos/JcWallet.cpp"
|
|
||||||
startingColumnNumber = "9223372036854775807"
|
|
||||||
endingColumnNumber = "9223372036854775807"
|
|
||||||
startingLineNumber = "160"
|
|
||||||
endingLineNumber = "160"
|
|
||||||
landmarkName = "tick(dt)"
|
|
||||||
landmarkType = "9">
|
|
||||||
</BreakpointContent>
|
|
||||||
</BreakpointProxy>
|
|
||||||
<BreakpointProxy
|
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
|
||||||
<BreakpointContent
|
|
||||||
uuid = "614B1FEA-6B61-4A25-BE89-9EE30D36CBC7"
|
|
||||||
shouldBeEnabled = "No"
|
|
||||||
ignoreCount = "0"
|
|
||||||
continueAfterRunningActions = "No"
|
|
||||||
filePath = "Classes_cocos/JcWallet.mm"
|
|
||||||
startingColumnNumber = "9223372036854775807"
|
|
||||||
endingColumnNumber = "9223372036854775807"
|
|
||||||
startingLineNumber = "225"
|
|
||||||
endingLineNumber = "225"
|
|
||||||
landmarkName = "jsb_scanQRCode(s)"
|
|
||||||
landmarkType = "9">
|
|
||||||
</BreakpointContent>
|
|
||||||
</BreakpointProxy>
|
|
||||||
<BreakpointProxy
|
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
|
||||||
<BreakpointContent
|
|
||||||
uuid = "8D9F9587-E7C9-406A-B764-D5BF90564CBA"
|
|
||||||
shouldBeEnabled = "No"
|
|
||||||
ignoreCount = "0"
|
|
||||||
continueAfterRunningActions = "No"
|
|
||||||
filePath = "Classes_cocos/UnityAppController+Wallet.mm"
|
|
||||||
startingColumnNumber = "9223372036854775807"
|
|
||||||
endingColumnNumber = "9223372036854775807"
|
|
||||||
startingLineNumber = "17"
|
|
||||||
endingLineNumber = "17"
|
|
||||||
landmarkName = "-scanQRCode:"
|
|
||||||
landmarkType = "7">
|
|
||||||
</BreakpointContent>
|
|
||||||
</BreakpointProxy>
|
|
||||||
<BreakpointProxy
|
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
|
||||||
<BreakpointContent
|
|
||||||
uuid = "AEC6EE3A-8956-46C2-A0A8-228945459762"
|
|
||||||
shouldBeEnabled = "No"
|
|
||||||
ignoreCount = "0"
|
|
||||||
continueAfterRunningActions = "No"
|
|
||||||
filePath = "Classes_cocos/UnityAppController+Wallet.mm"
|
|
||||||
startingColumnNumber = "9223372036854775807"
|
|
||||||
endingColumnNumber = "9223372036854775807"
|
|
||||||
startingLineNumber = "16"
|
|
||||||
endingLineNumber = "16"
|
|
||||||
landmarkName = "-scanQRCode:"
|
|
||||||
landmarkType = "7">
|
|
||||||
</BreakpointContent>
|
|
||||||
</BreakpointProxy>
|
|
||||||
<BreakpointProxy
|
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
|
||||||
<BreakpointContent
|
|
||||||
uuid = "E1B1CB90-A31C-4C83-A52E-CB9E520862CE"
|
|
||||||
shouldBeEnabled = "No"
|
|
||||||
ignoreCount = "0"
|
|
||||||
continueAfterRunningActions = "No"
|
|
||||||
filePath = "Classes_cocos/UIViewController+Wallet.mm"
|
|
||||||
startingColumnNumber = "9223372036854775807"
|
|
||||||
endingColumnNumber = "9223372036854775807"
|
|
||||||
startingLineNumber = "44"
|
|
||||||
endingLineNumber = "44"
|
|
||||||
landmarkName = "-scanQRCode:"
|
|
||||||
landmarkType = "7">
|
|
||||||
</BreakpointContent>
|
|
||||||
</BreakpointProxy>
|
|
||||||
<BreakpointProxy
|
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
|
||||||
<BreakpointContent
|
|
||||||
uuid = "546581C6-1C99-46B6-A9C2-F3DCBC1C78D4"
|
|
||||||
shouldBeEnabled = "No"
|
|
||||||
ignoreCount = "0"
|
|
||||||
continueAfterRunningActions = "No"
|
|
||||||
filePath = "Classes_cocos/UIViewController+Wallet.mm"
|
|
||||||
startingColumnNumber = "9223372036854775807"
|
|
||||||
endingColumnNumber = "9223372036854775807"
|
|
||||||
startingLineNumber = "23"
|
|
||||||
endingLineNumber = "23"
|
|
||||||
landmarkName = "-scanQRCode:"
|
|
||||||
landmarkType = "7">
|
|
||||||
</BreakpointContent>
|
|
||||||
</BreakpointProxy>
|
|
||||||
<BreakpointProxy
|
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
|
||||||
<BreakpointContent
|
|
||||||
uuid = "DACE477D-4E89-42F4-B0DB-F46C7EC5041B"
|
|
||||||
shouldBeEnabled = "No"
|
|
||||||
ignoreCount = "0"
|
|
||||||
continueAfterRunningActions = "No"
|
|
||||||
filePath = "Classes_cocos/UIViewController+Wallet.mm"
|
|
||||||
startingColumnNumber = "9223372036854775807"
|
|
||||||
endingColumnNumber = "9223372036854775807"
|
|
||||||
startingLineNumber = "24"
|
|
||||||
endingLineNumber = "24"
|
|
||||||
landmarkName = "-scanQRCode:"
|
|
||||||
landmarkType = "7">
|
|
||||||
</BreakpointContent>
|
|
||||||
</BreakpointProxy>
|
|
||||||
<BreakpointProxy
|
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
|
||||||
<BreakpointContent
|
|
||||||
uuid = "7D77739A-FDDA-4C97-A8EA-DBD76CECA30F"
|
|
||||||
shouldBeEnabled = "No"
|
|
||||||
ignoreCount = "0"
|
|
||||||
continueAfterRunningActions = "No"
|
|
||||||
filePath = "Classes_cocos/UIViewController+Wallet.mm"
|
|
||||||
startingColumnNumber = "9223372036854775807"
|
|
||||||
endingColumnNumber = "9223372036854775807"
|
|
||||||
startingLineNumber = "22"
|
|
||||||
endingLineNumber = "22"
|
|
||||||
landmarkName = "-scanQRCode:"
|
|
||||||
landmarkType = "7">
|
|
||||||
</BreakpointContent>
|
|
||||||
</BreakpointProxy>
|
|
||||||
</Breakpoints>
|
|
||||||
</Bucket>
|
</Bucket>
|
||||||
|
@ -234,8 +234,7 @@ function restoreFromMnemonic(funId, mnemonic, password) {
|
|||||||
|
|
||||||
function scanQRCode(funId, title) {
|
function scanQRCode(funId, title) {
|
||||||
try {
|
try {
|
||||||
jsb.scanQRCode(title);
|
jsb.scanQRCode(funId, title);
|
||||||
return JSON.stringify({errcode: 0});
|
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
return JSON.stringify({errcode: 1, errmsg: err});
|
return JSON.stringify({errcode: 1, errmsg: err});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user