This error occurred when I used WKWebView for redirection, and there was a requirement in the project to visit an online link and then switch to a local link when visiting a link.

After I finished the development, I found that it works well in iOS13 and above, but I reported this error in iOS12: Error Domain=NSPOSIXErrorDomain Code=1 “Operation not permitted” UserInfo={_WKRecoveryAttempterErrorKey=

, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <721C0E5C-E0C3-49FF-B7D7-A5D82451E09D>.<9>, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=1}

Finally, after testing, it was found that the WKWebView problem on iOS12, no direct solution has been found, one solution is: in iOS12, a WebView to access online links, a WebView to access local links. I’d appreciate it if you could tell me who has a solution.

The test code is as follows:

import UIKit import WebKit import ZipArchive class ViewController: UIViewController {override func viewDidLoad() {super.viewdidLoad () view.backgroundcolor =.white // Create a WebView let webConfiguration = WKWebViewConfiguration(); let jsStr = "var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); Meta. SetAttribute (' content 'and' width = device - width, initial - scale = 1.0, the maximum - scale = 1.0, the minimum - scale = 1.0, user-scalable=no'); document.getElementsByTagName('head')[0].appendChild(meta);" let wkUScript = WKUserScript.init(source: jsStr, injectionTime: WKUserScriptInjectionTime.atDocumentEnd, forMainFrameOnly: true) let wkuContentController = WKUserContentController.init() wkuContentController.addUserScript(wkUScript) webConfiguration.userContentController = wkuContentController let webView = WKWebView(frame: self.view.bounds, configuration: webConfiguration); webView.navigationDelegate = self webView.translatesAutoresizingMaskIntoConstraints = false; Webview.load (urlRequest.init (url: urlRequest.init (string: "https://www.baidu.com")!) ) began after open the local link / / / 5 s/local link I use here is a zip into local sandbox mode DispatchQueue. Main. AsyncAfter (deadline: .now() + 5) {// unzip let filePath = "\(NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).first!) /localHtml" if ! FileManager.default.fileExists(atPath: filePath) { let localPath = Bundle.main.path(forResource: "gui_dist.zip", ofType: nil) let zip = ZipArchive.init() zip.unzipOpenFile(localPath) zip.unzipFile(to: filePath, overWrite: True) let success = zip.unzipclosefile () print("unzipCloseFile ---- \(success)")} // Open local link let htmlUrl = URL.init(string: "file://\(filePath)/index.html") let fileUrl = URL.init(fileURLWithPath: filePath) webView.loadFileURL(htmlUrl! , allowingReadAccessTo:fileUrl) } } } extension ViewController: WKNavigationDelegate { func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation! , withError error: Error) { print("didFailProvisionalNavigation --- \(error)") } }Copy the code