我正在尝试使用 JSCore 从 Swift 中的 javascript SDK 执行异步函数。我已经能够完成评估和查看脚本的内容,但在实际调用异步函数时并未成功。这是我的代码,用于验证我是否已阅读该脚本。关于如何实现这一目标有什么想法吗?
lazy var context: JSContext? = {
let context = JSContext()
guard let
commonJSPath = Bundle.main.path(forResource: "test", ofType: "js") else {
print("Unable to read resource files.")
return nil
}
do {
let common = try String(contentsOfFile: commonJSPath, encoding: String.Encoding.utf8)
_ = context?.evaluateScript(common)
} catch (let error) {
print("Error while processing script file: \(error)")
}
return context
}()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from …Run Code Online (Sandbox Code Playgroud)