增加显示webpage的功能
This commit is contained in:
parent
710eab3063
commit
7f7ece3659
@ -465,6 +465,28 @@ bool JSB_showQRCode(se::State& s){
|
||||
}
|
||||
SE_BIND_FUNC(JSB_showQRCode)
|
||||
|
||||
bool jsb_showWebPage(se::State& s) {
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
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 url;
|
||||
ok = seval_to_std_string(args[1], &url);
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
NSString *nurl = [NSString stringWithCString:url.c_str() encoding:NSUTF8StringEncoding];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
|
||||
[window.rootViewController showPage:nurl];
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(jsb_showWebPage)
|
||||
|
||||
|
||||
bool jsb_register_walletevent_modules(se::Object* global) {
|
||||
getOrCreatePlainObject_r("jsb", global, &__jsbObj);
|
||||
@ -478,6 +500,7 @@ bool jsb_register_walletevent_modules(se::Object* global) {
|
||||
__jsbObj->defineFunction("signWithTwitter", _SE(jsb_signWithTwitter));
|
||||
__jsbObj->defineFunction("signOutGoogle", _SE(jsb_signOutGoogle));
|
||||
__jsbObj->defineFunction("showQRCode", _SE(JSB_showQRCode));
|
||||
__jsbObj->defineFunction("showWebPage", _SE(jsb_showWebPage));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -84,9 +84,9 @@ static SimpleQRViewController *sqrVC = nil;
|
||||
|
||||
-(void)beginScanQRCode:(NSString *)funid title:(NSString *) title{
|
||||
std::string sfunid = std::string([funid UTF8String], [funid lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
|
||||
__weak __typeof(self) weakSelf = self;
|
||||
// __weak __typeof(self) weakSelf = self;
|
||||
if ([QRCodeReader supportsMetadataObjectTypes:@[AVMetadataObjectTypeQRCode]]) {
|
||||
static dispatch_once_t onceToken;
|
||||
// static dispatch_once_t onceToken;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// if we are active again, we don't need to do this anymore
|
||||
|
@ -21,5 +21,6 @@
|
||||
-(void)signOutGoogle:(NSString *)funid;
|
||||
-(void)saveKey:(NSString *) account key:(NSString *) key;
|
||||
-(NSString *)loadKey:(NSString *) account;
|
||||
-(void)showPage:(NSString *)url;
|
||||
//-(void)nativeCb:(NSString *)funid hasErr: (BOOL) hasErr dataStr:(NSString *) dataStr;
|
||||
@end
|
||||
|
@ -6,7 +6,7 @@
|
||||
//
|
||||
|
||||
#import "UIViewController+Wallet.h"
|
||||
|
||||
#import "WebPageViewController.h"
|
||||
#import <TikTokOpenSDK/TikTokOpenSDKAuth.h>
|
||||
|
||||
#include <string>
|
||||
@ -19,12 +19,14 @@
|
||||
#import "AppleSignIn.h"
|
||||
#import <FBSDKLoginKit/FBSDKLoginKit.h>
|
||||
|
||||
|
||||
@import GoogleSignIn;
|
||||
|
||||
static NSString * const kClientID =
|
||||
@"53206975661-0d6q9pqljn84n9l63gm0to1ulap9cbk4.apps.googleusercontent.com";
|
||||
|
||||
|
||||
static WebPageViewController *webpageVC = nil;
|
||||
@implementation UIViewController (Wallet)
|
||||
|
||||
+(void)toWallet:(NSString *)url{
|
||||
@ -120,10 +122,10 @@ static NSString * const kClientID =
|
||||
request.permissions = scopesSet;
|
||||
|
||||
/* STEP 2: Send the request */
|
||||
__weak typeof(self) ws = self;
|
||||
// __weak typeof(self) ws = self;
|
||||
[request sendAuthRequestViewController:self
|
||||
completion:^(TikTokOpenSDKAuthResponse *_Nonnull resp) {
|
||||
__strong typeof(ws) sf = ws;
|
||||
// __strong typeof(ws) sf = ws;
|
||||
|
||||
/* STEP 3: Parse and handle the response */
|
||||
if (resp.errCode == 0) {
|
||||
@ -167,10 +169,8 @@ static NSString * const kClientID =
|
||||
|
||||
#pragma mark -- Sign In with Twitter
|
||||
- (void) signWithTwitter:(NSString *) funid {
|
||||
|
||||
}
|
||||
|
||||
|
||||
-(void)nativeCb:(NSString *)funid hasErr: (BOOL) hasErr dataStr:(NSString *) dataStr {
|
||||
if ([NSString isStringEmpty:funid]) {
|
||||
NSLog(@"nativeCallBack with empty funid: %@", funid);
|
||||
@ -188,4 +188,16 @@ static NSString * const kClientID =
|
||||
cocos2d::nativeCallBack(sfunid.c_str(), methodName.c_str(), sparam.c_str());
|
||||
}
|
||||
|
||||
#pragma mark -- show webpage
|
||||
|
||||
-(void)showPage:(NSString *)url{
|
||||
if (webpageVC == nil) {
|
||||
webpageVC = [WebPageViewController new];
|
||||
}
|
||||
webpageVC.url = url;
|
||||
self.definesPresentationContext = YES;
|
||||
webpageVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
|
||||
[self presentViewController:webpageVC animated:YES completion:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
16
Classes_cocos/WebPageViewController.h
Normal file
16
Classes_cocos/WebPageViewController.h
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// WebPageViewController.h
|
||||
// Unity-iPhone
|
||||
//
|
||||
// Created by Hl Zhang on 2023/3/14.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface WebPageViewController : UIViewController
|
||||
@property (nonatomic, copy) NSString* url;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
44
Classes_cocos/WebPageViewController.m
Normal file
44
Classes_cocos/WebPageViewController.m
Normal file
@ -0,0 +1,44 @@
|
||||
//
|
||||
// WebPageViewController.m
|
||||
// Unity-iPhone
|
||||
//
|
||||
// Created by Hl Zhang on 2023/3/14.
|
||||
//
|
||||
|
||||
#import "WebPageViewController.h"
|
||||
#import <WebKit/WebKit.h>
|
||||
|
||||
#define SCREENWIDTH [UIScreen mainScreen].bounds.size.width
|
||||
#define SCREENHEIGHT [UIScreen mainScreen].bounds.size.height
|
||||
|
||||
|
||||
@interface WebPageViewController ()
|
||||
@property (nonatomic, strong) WKWebView *webView;
|
||||
@end
|
||||
|
||||
@implementation WebPageViewController
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
// Create the WKWebView
|
||||
self.webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
|
||||
[self.view addSubview:self.webView];
|
||||
|
||||
// Load the URL
|
||||
NSURL *url = [NSURL URLWithString:self.url];
|
||||
NSURLRequest *request = [NSURLRequest requestWithURL:url];
|
||||
[self.webView loadRequest:request];
|
||||
}
|
||||
|
||||
/*
|
||||
#pragma mark - Navigation
|
||||
|
||||
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
||||
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
||||
// Get the new view controller using [segue destinationViewController].
|
||||
// Pass the selected object to the new view controller.
|
||||
}
|
||||
*/
|
||||
|
||||
@end
|
@ -79,6 +79,12 @@
|
||||
<key>NSAllowsArbitraryLoads</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>NSCameraUsageDescription</key>
|
||||
<string>The camera is need to scan QR codes</string>
|
||||
<key>NSMicrophoneUsageDescription</key>
|
||||
<string>THe microphoe is need to talk in game.</string>
|
||||
<key>NSPhotoLibraryUsageDescription</key>
|
||||
<string>Restore Wallet recovery key need Photo Libray</string>
|
||||
<key>SKAdNetworkItems</key>
|
||||
<array>
|
||||
<dict>
|
||||
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -126,8 +126,8 @@
|
||||
filePath = "../../crypto/cocos_js/cocos/scripting/js-bindings/manual/jsb_global.cpp"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "1179"
|
||||
endingLineNumber = "1179"
|
||||
startingLineNumber = "1177"
|
||||
endingLineNumber = "1177"
|
||||
landmarkName = "JSB_loadLocalStorage(s)"
|
||||
landmarkType = "9">
|
||||
</BreakpointContent>
|
||||
@ -142,8 +142,8 @@
|
||||
filePath = "../../crypto/cocos_js/cocos/scripting/js-bindings/manual/jsb_global.cpp"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "1180"
|
||||
endingLineNumber = "1180"
|
||||
startingLineNumber = "1178"
|
||||
endingLineNumber = "1178"
|
||||
landmarkName = "JSB_loadLocalStorage(s)"
|
||||
landmarkType = "9">
|
||||
</BreakpointContent>
|
||||
|
File diff suppressed because one or more lines are too long
12
js/main.js
12
js/main.js
@ -214,9 +214,19 @@ function showQRCode(funId, content) {
|
||||
}
|
||||
}
|
||||
|
||||
function showWebPage(funId, url) {
|
||||
try {
|
||||
// jsb.showWebPage(funId, url);
|
||||
jsb.openURL(url);
|
||||
return JSON.stringify({ errcode: 0, data: 1 });
|
||||
} catch (err) {
|
||||
return JSON.stringify({ errcode: 1, errmsg: err });
|
||||
}
|
||||
}
|
||||
|
||||
function scanQRCode(funId, title) {
|
||||
console.log('scanQRCode: ' + title)
|
||||
jc.wallet.nativeSvr.scanQRCode(title)
|
||||
jc.wallet.scanQr(title)
|
||||
.then((result)=> {
|
||||
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user