diff --git a/.DS_Store b/.DS_Store index bb2a1d4..d1bed2e 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/assets/btn_click.ts b/assets/btn_click.ts index 11bb6d0..2c34868 100644 --- a/assets/btn_click.ts +++ b/assets/btn_click.ts @@ -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", @@ -96,6 +108,7 @@ export class btn_click extends Component { }; var jsonStr = JSON.stringify(jsonObj); ///0x2eB535d54382eA5CED9183899916A9d39e093877 + var ret = native.reflection.callStaticMethod( "JSHandleClass", @@ -103,4 +116,11 @@ export class btn_click extends Component { jsonStr ); } + + public setAddress(add: string) { + this.address = add; + } + + + } diff --git a/native/engine/android/app/src/com/cocos/game/.DS_Store b/native/engine/android/app/src/com/cocos/game/.DS_Store index f3711bc..5cc8d75 100644 Binary files a/native/engine/android/app/src/com/cocos/game/.DS_Store and b/native/engine/android/app/src/com/cocos/game/.DS_Store differ diff --git a/native/engine/ios/JSHandleClass.m b/native/engine/ios/JSHandleClass.m index 39fcf26..30d135a 100644 --- a/native/engine/ios/JSHandleClass.m +++ b/native/engine/ios/JSHandleClass.m @@ -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"); } diff --git a/native/engine/ios/WalletConnect.swift b/native/engine/ios/WalletConnect.swift index 412246f..417936c 100644 --- a/native/engine/ios/WalletConnect.swift +++ b/native/engine/ios/WalletConnect.swift @@ -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", diff --git a/native/engine/ios/cocos_demo_3-mobile-Bridging-Header.h b/native/engine/ios/cocos_demo_3-mobile-Bridging-Header.h index 1b2cb5d..79b5e5c 100644 --- a/native/engine/ios/cocos_demo_3-mobile-Bridging-Header.h +++ b/native/engine/ios/cocos_demo_3-mobile-Bridging-Header.h @@ -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" diff --git a/native/engine/ios/myWalletConnect.swift b/native/engine/ios/myWalletConnect.swift index 39ae5e9..945c44d 100644 --- a/native/engine/ios/myWalletConnect.swift +++ b/native/engine/ios/myWalletConnect.swift @@ -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") } } }