- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 WKWebView
来提供单页网络应用 (ember) 的 index.html
,如下所示:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let webview = WKWebView(
frame: view.frame,
configuration: WKWebViewConfiguration()
)
view.addSubview(webview)
let root = NSBundle.mainBundle().resourceURL!
let url = root.URLByAppendingPathComponent("dist/index.html")
webview.loadFileURL(url, allowingReadAccessToURL: root)
加载索引文件效果很好。但是索引文件正在使用文件方案请求它的链接和资源?如果我在检查器中运行时使用 Safari 检查应用程序,我会看到所有本地资源的错误:
[Error] Failed to load resource: ... file:///dist/assets/css/vendor.css
在 index.html
中看起来像:
<link rel="stylesheet" href="./dist/assets/vendor.css">
我想要的是资源请求转到我的 GCDWebServer我这样设置的:
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var webServer: GCDWebServer?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.webServer = GCDWebServer()
self.webServer!.addGETHandlerForBasePath("/",
directoryPath: NSBundle.mainBundle().bundlePath,
indexFilename: nil,
cacheAge: 3600,
allowRangeRequests: true
)
self.webServer!.startWithPort(8080, bonjourName: "GCD Web Server")
print("GCD Server running at: \(self.webServer!.serverURL)")
return true
并且我已将 dist
文件夹添加到 Xcode 中的包中。
我在这里错过了什么?
最佳答案
这就是 HTML 的工作原理。不是绝对的 HREF 是相对于引用页面的来源的。所以如果你有 images/foo.png
在 file:///dir/index.html
, 浏览器会请求 file:///dir/images/foo.png
.
如果您需要浏览器从不同位置获取资源,则需要在 HTML 中使用绝对 URL(例如 http://localhost:8080/whatever
)。
关于ios - 为什么我的 XWebView 使用文件方案提供 index.html,我该如何更改它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33059197/
我想知道是否有可能将 JavaScript 控制台的输出显示到 XCode 编辑器中的控制台。我们在 iOS 8 上使用 XWebView。 谷歌搜索似乎没有帮助。我真的不知道。 最佳答案 有一个新的
我正在我的 swift 项目中使用 XWebView 框架,我正在将 native 对象传递给 javascript我已经在我的项目中成功集成了 XWebView 框架。但是当我创建一个 IPA 时,
我正在使用 WKWebView 来提供单页网络应用 (ember) 的 index.html,如下所示: class ViewController: UIViewController { ov
我是一名优秀的程序员,十分优秀!