【问题标题】:check Javascript library version in iOS swift在 iOS swift 中检查 Javascript 库版本
【发布时间】:2021-10-20 08:40:31
【问题描述】:

我需要调用 Tronweb.js ,然后调用 trxSendTest.js。所以需要检查 Tronwebis 是否被调用。

输出-

版本 = 未定义 版本未定义

    do {
        let TronWebJS = try String(contentsOf: Bundle.main.url(forResource: "TronWeb", withExtension: "js")!, encoding: .utf8)
        let trxSendTest = try String(contentsOf: Bundle.main.url(forResource: "trxSendTest", withExtension: "js")!, encoding: .utf8)
        
        
        
        jsContext?.evaluateScript(TronWebJS)
        jsContext?.evaluateScript(trxSendTest)
        
        let testFunction = jsContext?.objectForKeyedSubscript("tronweb.version.api")
        print("version = \(testFunction!)")
        

        
        
        if let version = jsContext?.evaluateScript("tronweb.version.api") {
            print("version is \(version)")
        }
    }
    catch {
        print("An error occurred")
    }

【问题讨论】:

  • 请描述您遇到的问题。输出是什么还是你得到了错误?
  • version = undefined 版本未定义
  • 我需要调用 Tronweb.js ,Tronweb.js 已添加到 Xcode 中。

标签: javascript ios swift xcode javascriptcore


【解决方案1】:

tronweb.versionpackage.json的内容,应该在tronweb包的根目录下。也可以在github上找到,https://github.com/tronprotocol/tronweb/blob/247a1eaf6d8fbf433282e1b4efc0ad4de4c673a8/package.json

你可以试试tronweb.version.version,而不是tronweb.version.api

【讨论】:

    猜你喜欢
    • 2014-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-22
    • 1970-01-01
    • 2015-11-14
    • 1970-01-01
    相关资源
    最近更新 更多