1
我嘗試運行GCDWebServer以便從它要使用的相同設備訪問它。GCDWebServer 500錯誤
我有下面的代碼
import UIKit
import Foundation
import WebKit
class ViewController: UIViewController, WKNavigationDelegate {
var webServer: GCDWebServer?
var webView: WKWebView?
let urlpath : NSString = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.AllDomainsMask, true).first!
override func viewDidLoad() {
super.viewDidLoad()
webView = WKWebView(frame: CGRectMake(0, 0, 300, 300))
webView?.navigationDelegate = self
view.addSubview(webView!)
initWebServer()
let urlString:String = "\(webServer!.serverURL)index.html"
let url = NSURL(string: urlString)!
webView!.loadRequest(NSURLRequest(URL: url))
}
func initWebServer() {
webServer = GCDWebServer()
webServer!.addGETHandlerForBasePath("/", directoryPath: urlpath as String, indexFilename: "index.html", cacheAge: 3600, allowRangeRequests: true)
webServer!.startWithPort(8080, bonjourName: "GCD Web Server")
print("Visit \(webServer!.serverURL) in your web browser")
}
在控制檯我有以下輸出
如何使它工作?