How to load WebAssembly in iOS app via WKWebVIew or JSC
Asked Answered
A

2

10

I'm trying to load and execute a WebAssembly .wasm from within a Swift-based, iOS app. I first attempted to use the JavaScriptCore Framework but the WebAssembly.* module wasn't available in the Context when I tried to evaluate a trivial script. I was able to confirm the WebAssembly isn't defined via the Safari Debugger Console.

I then attempted to use WKWebView because I'm led to believe that the lack of WebAssembly is due to JSC not supporting JIT, which WKWebView should. I got the same result.

Here's a trivial app running on an iPhone X 12.4 emulator, Xcode 10.3 and the WebKit Framework manually added to the project. Make sure to open Safari and Select "Developer>Simulator" for WKWebView debugger.

import UIKit
import WebKit

class ViewController: UIViewController {
    @IBOutlet weak var webView: WKWebView!

    override func viewDidLoad() {
        super.viewDidLoad()
    }
    @IBAction func onClick(_ sender: UIButton) {
        let testWasm = """
            if(typeof WebAssembly !== 'undefined') {
                console.log("Hello, Wasm.");
            } else {
                console.log("No Wasm for you!");
            }
        """

        webView.evaluateJavaScript(testWasm)
    }
}

Does iOS actually have a way to load WebAssembly into a Swift-based app?

Achromatism answered 4/8, 2019 at 17:32 Comment(1)
I think it is due to this bug: bugs.webkit.org/show_bug.cgi?id=191064 I've only been testing in the simulator!Achromatism
D
3

I wanted to run some benchmarks with JSC to compare it with Wasm3.
Basically I run into the same situation and wasn't able to fix so far.

Wasm3 runs perfectly fine on iOS, and may suite your needs at the moment.

Currently you can't run WebAssembly with JSC on the simulator according to this comment.

Del answered 15/1, 2020 at 16:56 Comment(0)
M
3

It appears that JavaScriptCore now has a WebAssembly interpreter, as of Feb 2020.

Maxson answered 20/8, 2021 at 18:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.