From 073cef8f2f764a183ebbcff7afc8df048a01f2bf Mon Sep 17 00:00:00 2001 From: Etrent Date: Mon, 17 Oct 2022 18:12:18 +0800 Subject: [PATCH] save --- .DS_Store | Bin 8196 -> 8196 bytes assets/btn_click.ts | 24 ++++++++++++++++-- .../android/app/src/com/cocos/game/.DS_Store | Bin 6148 -> 6148 bytes native/engine/ios/JSHandleClass.m | 3 +++ native/engine/ios/WalletConnect.swift | 2 +- .../ios/cocos_demo_3-mobile-Bridging-Header.h | 1 + native/engine/ios/myWalletConnect.swift | 10 +++++--- 7 files changed, 34 insertions(+), 6 deletions(-) diff --git a/.DS_Store b/.DS_Store index bb2a1d475c86bb29d5f8f5ad36d98f1398f77553..d1bed2ee5c5382938550509c22061cb578e74b3e 100644 GIT binary patch delta 25 gcmZp1XmQw3BgkQ5Y@(xJY+^9^n~?qH!-9@{0BEHL`~Uy| delta 16 XcmZp1XmQw3BRKh;ko)Gtf{uIuI@bnv 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 f3711bca8abb2551112ec8696d4ad8560e24c9c0..5cc8d7511256b9644d11f35822f5f58bfe7ac25e 100644 GIT binary patch delta 355 zcmZoMXfc=|#>B)qu~2NHo+2a5!~pA!4;mPOj2`=XHilq^RE8pkG7#yRlb@WFlb^)E zz#ss`>w#GBKNtX63=Al0lgf(=plWv{735?VmlzmaV`O4xVP#|IVCUfGhz-ujFApwB zEGaE^N-T;7@j~+RbCO`}#H6sy)cW#x0TJi?ypqJsywoDFj?9!)pqiNQ%)FHRa;N;# zyp&?F=3s~f2PX$-ynsY?wV9ELj)IZ7Nv)1TwWX1Pj)IAqNo_4Bhp4i?bx?eEPHtX) z7ueYhjEoSPffq`{sBQ*nG+&hk7v<&T=cNNxFmAlKm}N6N2R{ce>^5Hf&ODi4#83ca RR0BvBj2IX;2Z(H81^~+8T&Vy6 delta 64 zcmZoMXfc=|#>CJ*u~2NHo+2aT!~knX#>qTP_M6L?C$emAU|!9%nVo~51E^$kA@g_U U$^0UQj0}@)c%(PSh^$}+06#GiV*mgE 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") } } }