嗨我正在尝试使用WKWebView加载一个主要Bundle中的html,这与UIWebView完美配合,但现在我有一个错误,html中的文件没有加载在控制台中发送错误:"XMLHttpRequest无法加载"
这是嵌入内容的http://proyectoshm.com/esferas/dosaguas/dosaguascitta.html示例.
我的代码:
let folder = "maquetas/esferas/\(esfera)"
let resourcePath = Bundle.main.resourcePath
let subdir = URL(fileURLWithPath:resourcePath!).appendingPathComponent(folder, isDirectory: true)
guard let path = Bundle.main.path(forResource: "index", ofType: "html", inDirectory: folder) else {
print("no se encontró path")
return
}
print(subdir.path)
let url = NSURL.fileURL(withPath: path)
print(url.path)
vistaweb = WKWebView(frame: self.view.frame)
vistaweb.loadFileURL(url, allowingReadAccessTo: subdir)
self.view.addSubview(vistaweb)
Run Code Online (Sandbox Code Playgroud) 当我实现这个方法时,我有一个非常奇怪的MKMapViewDelegate问题给我一个我不明白的错误
当我删除整个函数时,错误才消失,
我试图让一个空函数返回nil,但给我同样的错误.
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if annotation.isKindOfClass(MKUserLocation.classForCoder()) {
return nil
}
let AnnotationIdentifier:NSString = "AnnotationIdentifier"
var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(AnnotationIdentifier)
if annotationView != nil {
return annotationView
}else {
var annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: AnnotationIdentifier)
annotationView.canShowCallout = true
annotationView.image = UIImage(named: "btn_fav.png")
return annotationView
}
}
Run Code Online (Sandbox Code Playgroud)
错误:命令因信号失败:分段错误:11
CompileSwift normal arm64 /Users/Fortis/Proyectos/IOS Apps/Abilia/Abilia iOS/Abilia/Abilia/Vistas/Proyecto/MapaViewController.swift
cd /Users/Fortis/Proyectos/IOS Apps/Abilia/Abilia iOS/Abilia
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c "/Users/Fortis/Proyectos/IOS Apps/Abilia/Abilia iOS/Abilia/Abilia/Classes/NetClass/Downloader.swift" -primary-file "/Users/Fortis/Proyectos/IOS Apps/Abilia/Abilia iOS/Abilia/Abilia/Vistas/Proyecto/MapaViewController.swift" "/Users/Fortis/Proyectos/IOS Apps/Abilia/Abilia iOS/Abilia/Abilia/Vistas/Widget/ToggleView.swift" .
Run Code Online (Sandbox Code Playgroud)
...
0 …Run Code Online (Sandbox Code Playgroud) 我有一个完全在模拟器中工作的WKWebView,但为什么在设备中只运行一个白色空屏幕,这是我的代码:
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
webConfiguration.preferences.setValue(true, forKey:"allowFileAccessFromFileURLs")
webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.uiDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
let path2Esferas = Path.localPath.stringByAppendingPathComponent(path: "\(Path.DIR_IMAGES)\(ImagenDescargaTipo.esfera.rawValue)/\(desarrollo.id)/virtualtour.html")
let url = URL(fileURLWithPath: path2Esferas)
//NSURL.fileURL(withPath: path2Esferas)
let myRequest = URLRequest(url: url)
webView.load(myRequest)
}
Run Code Online (Sandbox Code Playgroud)
在"path2Esferas"的HTML是在高速缓存中的文件夹,我以前加载,如果我把不同的URL一样let myURL = URL(string: "https://www.apple.com")的文档显示,它工作正常在模拟器和设备.例如:http://proyectoshm.com/esferas/real_de_mina/realdeminas.html