This commit is contained in:
Etrent 2022-10-17 18:12:18 +08:00
parent ba1aa39ac3
commit 073cef8f2f
7 changed files with 34 additions and 6 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -2,9 +2,21 @@ import { _decorator, Component, Node, native,sys } from "cc";
const { ccclass, property } = _decorator;
import { createRequestData } from "./WalletSdkUtils";
@ccclass("btn_click")
export class btn_click extends Component {
start() { }
public address: string;
start() {
window["setAddress"] = this.setAddress.bind(this);
native.bridge.onNative = (add: string): void => {
console.log(`触发了回调!回调内容:${add}`)
this.setAddress(add)
return;
}
}
update(deltaTime: number) { }
/**
@ -41,7 +53,7 @@ export class btn_click extends Component {
public async btn_onclick2() {
console.info("点击了按钮");
var temp = createRequestData(
"0x4eDE150f62dc21aDC0F39a2A02c95A5Cc1FD7B2C",
this.address,
"0x62cC9fd83d48eFCe313695bA6a3245bCCC7f196e",
"Mint",
"0x4eDE150f62dc21aDC0F39a2A02c95A5Cc1FD7B2C",
@ -97,10 +109,18 @@ export class btn_click extends Component {
var jsonStr = JSON.stringify(jsonObj);
///0x2eB535d54382eA5CED9183899916A9d39e093877
var ret = native.reflection.callStaticMethod(
"JSHandleClass",
"sendMessageFun:",
jsonStr
);
}
public setAddress(add: string) {
this.address = add;
}
}

View File

@ -8,12 +8,15 @@
#import "JSHandleClass.h"
#import "cocos_demo_3_mobile-Swift.h"
MyWalletConnect* wc;
@implementation JSHandleClass
+ (void) init{
wc =[MyWalletConnect alloc];
[wc initWalleConnect];
NSLog(@"调用到了init");
}

View File

@ -26,7 +26,7 @@ class WalletConnect {
// gnosis wc bridge: https://safe-walletconnect.gnosis.io/
// test bridge with latest protocol version: https://bridge.walletconnect.org
let wcUrl = WCURL(topic: UUID().uuidString,
bridgeURL: URL(string: "https://safe-walletconnect.gnosis.io/")!,
bridgeURL: URL(string: "https://bridge.walletconnect.org")!,
key: try! randomKey())
let clientMeta = Session.ClientMeta(name: "ExampleDApp",
description: "WalletConnectSwift",

View File

@ -2,3 +2,4 @@
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import "cocos/platform/apple/JsbBridge.h"

View File

@ -28,7 +28,7 @@ import WalletConnectSwift
///
func walleConnectFun(urlTypeStr:String)->Void{
let deepLinkUrl = "wc"+"://wc?uri=\(cr!)"
let deepLinkUrl = urlTypeStr+"://wc?uri=\(cr!)"
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
if let url = URL(string: deepLinkUrl), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
@ -130,14 +130,18 @@ extension MyWalletConnect: WalletConnectDelegate {
func didConnect() {
onMainThread { [unowned self] in
print("session+++++==============\(walletConnect.session.url)")
print("session+++++==============\(walletConnect.session.walletInfo?.accounts)")
var aa = JsbBridge.sharedInstance();
aa?.send(toScript:walletConnect.session.walletInfo?.accounts[0]);
// JsbBridgeWrapper* m = [JsbBridgeWrapper sharedInstance]
print("链接成功")
NSLog("didConnect")
}
}
func didDisconnect() {
onMainThread { [unowned self] in
NSLog("didConnect")
NSLog("didDisconnect")
}
}
}