Search code examples
iosswifthybrid

Crosswalks on ios - can not find the XWalkView module


I am trying to use crosswalk to make my web app into iOS app
and I following the steps of Quickstart in this page https://github.com/crosswalk-project/crosswalk-ios but I keep facing the problem:
in the ViewController.swift
When I import XWalkView, It always appears that It can't find the XWalkView module which makes me stop from my development...

Somebody help me.

Here's the code of ViewController.swift:

import UIKit
import WebKit
import XWalkView

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        var start_url = "index.html"
        var xwalk_extensions = ["Extension.load"]
        if let plistPath = NSBundle.mainBundle().pathForResource("manifest", ofType: "plist") {
            if let manifest = NSDictionary(contentsOfFile: plistPath) {
                start_url = manifest["start_url"] as? String ?? start_url
                xwalk_extensions = manifest["xwalk_extensions"] as? [String] ?? xwalk_extensions
            }
        }

        let webview = WKWebView(frame: view.frame, configuration: WKWebViewConfiguration())
        webview.scrollView.bounces = false
        view.addSubview(webview)

        for name in xwalk_extensions {
            if let ext: AnyObject = XWalkExtensionFactory.createExtension(name) {
                webview.loadExtension(ext, namespace: name)
            }
        }

        if let root = NSBundle.mainBundle().resourceURL?.URLByAppendingPathComponent("www") {
            var error: NSError?
            let url = root.URLByAppendingPathComponent(start_url)
            if url.checkResourceIsReachableAndReturnError(&error) {
                webview.loadFileURL(url, allowingReadAccessToURL: root)
            } else {
                webview.loadHTMLString(error!.description, baseURL: nil)
            }
        }
    }

    override func prefersStatusBarHidden() -> Bool {
        return true
    }
}

Solution

  • perhaps you forget to link the XWalkView.framework in your app target?

    Try this step: Open Xcode, select your app project, in 'General' -> 'Linked Frameworks and Libraries', select '+', choose 'XWalkView.framework' to add it into the linking frameworks. Then shot another build. It's ok if the XWalkView.framework turns red.