Post

Replies

Boosts

Views

Activity

WKWebView: Error when loading file from memory - SwiftUI
I am trying to load a file from memory and preview it in a WebView in SwiftUI. I already made the same procedure in Swift and it's working, but it's not working in SwiftUI. Files and successfully save to memory and retrieved, but I am getting this error: WebPageProxy::didFailProvisionalLoadForFrame: frameID=3, domain=NSPOSIXErrorDomain, code=1, isMainFrame=1 This function will return the WebView private func createURL() -> AnyView{ DocumentManager.shared.save(text: "Hey dear", toDirectory: DocumentManager.shared.documentDirectory(), withFileName: "test345.docx") let fileURL = DocumentManager.shared.read(fromDocumentsWithFileName: "test345.docx") return AnyView(Webview(url: URL(fileURLWithPath: fileURL))) } This is my UIViewRepresentable: struct Webview: UIViewRepresentable { let url: URL let navigationHelper = WebViewHelper() func makeUIView(context: UIViewRepresentableContext<Webview>) -> WKWebView { let webview = WKWebView() webview.navigationDelegate = navigationHelper let request = NSURLRequest(url: url as URL) as URLRequest webview.load(request) return webview } func updateUIView(_ webview: WKWebView, context: UIViewRepresentableContext<Webview>) { let request = URLRequest(url: self.url, cachePolicy: .returnCacheDataElseLoad) webview.load(request) } } And this is my WebView helper class: class WebViewHelper: NSObject, WKNavigationDelegate { func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { print("webview didFinishNavigation") } func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) { print("didStartProvisionalNavigation") } func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) { print("webviewDidCommit") } func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { print("didReceiveAuthenticationChallenge") completionHandler(.performDefaultHandling, nil) } }
0
0
1.8k
May ’22
Unable to push or pull
I committed some changes in my Xcode project and tried to push them, but I am prompted with: "The local repository is out of date." Then I tried to pull as they said, but then I am prompted with: "The working copy has conflicting, uncommitted changes." I really need to commit these changes, and I am scared of losing them if I do any wrong step. What should I do? Thanks
0
0
929
Feb ’22
WKWebView: Error when loading file from memory - SwiftUI
I am trying to load a file from memory and preview it in a WebView in SwiftUI. I already made the same procedure in Swift and it's working, but it's not working in SwiftUI. Files and successfully save to memory and retrieved, but I am getting this error: WebPageProxy::didFailProvisionalLoadForFrame: frameID=3, domain=NSPOSIXErrorDomain, code=1, isMainFrame=1 This function will return the WebView private func createURL() -> AnyView{ DocumentManager.shared.save(text: "Hey dear", toDirectory: DocumentManager.shared.documentDirectory(), withFileName: "test345.docx") let fileURL = DocumentManager.shared.read(fromDocumentsWithFileName: "test345.docx") return AnyView(Webview(url: URL(fileURLWithPath: fileURL))) } This is my UIViewRepresentable: struct Webview: UIViewRepresentable { let url: URL let navigationHelper = WebViewHelper() func makeUIView(context: UIViewRepresentableContext<Webview>) -> WKWebView { let webview = WKWebView() webview.navigationDelegate = navigationHelper let request = NSURLRequest(url: url as URL) as URLRequest webview.load(request) return webview } func updateUIView(_ webview: WKWebView, context: UIViewRepresentableContext<Webview>) { let request = URLRequest(url: self.url, cachePolicy: .returnCacheDataElseLoad) webview.load(request) } } And this is my WebView helper class: class WebViewHelper: NSObject, WKNavigationDelegate { func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { print("webview didFinishNavigation") } func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) { print("didStartProvisionalNavigation") } func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) { print("webviewDidCommit") } func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { print("didReceiveAuthenticationChallenge") completionHandler(.performDefaultHandling, nil) } }
Replies
0
Boosts
0
Views
1.8k
Activity
May ’22
Unable to push or pull
I committed some changes in my Xcode project and tried to push them, but I am prompted with: "The local repository is out of date." Then I tried to pull as they said, but then I am prompted with: "The working copy has conflicting, uncommitted changes." I really need to commit these changes, and I am scared of losing them if I do any wrong step. What should I do? Thanks
Replies
0
Boosts
0
Views
929
Activity
Feb ’22