Posts

Post not yet marked as solved
1 Replies
So does this mean its not possible? The subject has been brought up before but its outdated and unanswered so I feel it would be helpful for many to have an answer on this? Thank you.
Post marked as solved
13 Replies
Thanks again for all your help Quinn, I am now at this point, at first it was blocking the webview itself from working, but I moved the self navigation callout line below the view did Load and down below, and now the app works again, but it still doesn't allow the link to open? I tried putting the self navigation callout between but then it failed saying it needed a declaration. I understand what you did now, but I still can't get the links to open in the app? ----------------------------import UIKitimport WebKitclass ViewController: UIViewController,WKNavigationDelegate { @IBOutlet weak var loadhtml: WKWebView! override func viewDidLoad(){ super.viewDidLoad() let webView = WKWebView() let htmlURL = Bundle.main.url(forResource: "index", withExtension: "html", subdirectory: "www")! webView.loadFileURL(htmlURL, allowingReadAccessTo: htmlURL.deletingLastPathComponent()) view = webView } func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { webView.navigationDelegate = self if let host = navigationAction.request.url?.host{ if host.contains("innovateengineering.pro"){ decisionHandler(.allow) return } } decisionHandler(.cancel) }}--------------------------------
Post marked as solved
13 Replies
Well, I have this after a lot of reading and it still doesn't work. I must still be missing something...I substituted "xyz.com" for my url just for illustration purposes for anyone reading this in the future. You can likely see I am very limited in understanding the code. I think most of the instructions assume you know what you are doing so they leave most of the details out and it makes it hard to understand what goes where. Suggestions?----------------------import UIKitimport WebKitclass ViewController: UIViewController,WKNavigationDelegate { @IBOutlet weak var loadhtml: WKWebView! override func viewDidLoad() { super.viewDidLoad() let webView = WKWebView() webView.navigationDelegate = self let htmlURL = Bundle.main.url(forResource: "index", withExtension: "html", subdirectory: "www")! webView.loadFileURL(htmlURL, allowingReadAccessTo: htmlURL.deletingLastPathComponent()) view = webView func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { if let host = navigationAction.request.url?.host { if host.contains("xyz.com") { decisionHandler(.allow) return } } decisionHandler(.cancel) } }}----------------------Thanks again for all your help...
Post marked as solved
13 Replies
Also, as I spend hours trying to fix the problem, it's possibly I may be attemping to fix the wrong problem first. My links work fine in the html in safari, etc. However, the links embedded in the webview do absoultely nothing in the app. They don't open in the app either, I'm not even sure you can click on it. Is there something I need to enable in xcode to allow it to access the network, etc? I'll keep searching in the meantime...
Post marked as solved
13 Replies
So I have been trying several different code methods I found using your initial ideas and I have gotten the build to run in the simulator with this code in the view controller. However, no matter what I do it seems it either fails or succeeds but doesn't fix the broken links. I also tried putting it in the app delegate and moving it above and below the } view did load brackets, but it didn't seem to make a difference. I tried running the code with WKWebview instead of UIWebview and it kept failing with errors. Maybe i shouldn't be mixing in this UIWebviewDelegate, I don't know. Please advise. What am I missing?----------------------import UIKitimport WebKitclass ViewController: UIViewController, WKNavigationDelegate, UIWebViewDelegate { @IBOutlet weak var loadhtml: WKWebView! override func viewDidLoad() { super.viewDidLoad() let webView = WKWebView() let htmlURL = Bundle.main.url(forResource: "index", withExtension: "html", subdirectory: "www")! webView.loadFileURL(htmlURL, allowingReadAccessTo: htmlURL.deletingLastPathComponent()) view = webView } func webView(_: UIWebView, shouldStartLoadWith: URLRequest, navigationType: UIWebView.NavigationType) -> Bool { if navigationType == UIWebView.NavigationType.linkClicked { UIApplication.shared.open(shouldStartLoadWith.url!, options: [:], completionHandler: nil) return false } return true } }-----------------------Thanks again for all your help...
Post marked as solved
13 Replies
Thank you Quinn, I will look into this navigation delegate and see if i can make sense of it. You've been a big help. I'll get back to you with my results.As for the font size slider, it is embedded in the html and CSS, which works fine in Safari, Chrome, Explorer, etc. It isn't until I put it in xcode and make an app out of it that it stops working, so I feel like it is something to do with a limitation of webview? I was wondering if there is something i can do to "allow" it to function again?Thank you,Heath
Post marked as solved
13 Replies
Thnak you very much again, it works! When you had me check the app package contents, the www folder wasn't there. I made a mistake when I was trying different things to fix it, and I copied the whole folder and opened the new project. Well, I don't think it was referencing the right project anymore. So although we fixed the code it still wasn't finding the files. So I opened a new fresh project in an empy folder, and I created the new app with this (I took your advice and shortened the code)-------------------------import UIKitimport WebKitclass ViewController: UIViewController { @IBOutlet weak var loadhtml: WKWebView! override func viewDidLoad() { super.viewDidLoad() let webView = WKWebView() let htmlURL = Bundle.main.url(forResource: "index", withExtension: "html", subdirectory: "www")! webView.loadFileURL(htmlURL, allowingReadAccessTo: htmlURL.deletingLastPathComponent()) view = webView }}-------------------------The app works now! Thank you so much for the help, I really appreciate it. I do have two questions though.1 - There is a web link within my app, and it does not work, you click on it in the simulator and nothing happens. Do I need to add code for this to work? It should open in Safari?2 - I have a slider to change the font size for a tablet vs a phone, etc. It works great in the local html & css in Safari but it doesn't work in the app. Is there something i need to add to allow that to change in the app? The slider is there and works but you slide it and nothing happens.Thanks again so much!
Post marked as solved
13 Replies
Thank you so much for the help, I really appreciate it!I tried what you asked and I also deleted and reinserted the "www" folder making sure the "create folder references" was checked, and also the "add to targets" was checked on the main app file. The html, css, javascript, etc. code works fine if I click on the "index.html" in the finder and open it in safari, works as expected.I tried using: let htmlPath = Bundle.main.path(forResource: "index", withExtension: "html", subDirectory: "www")But it made me return it to: let htmlPath = Bundle.main.path(forResource: "index", ofType: "html", inDirectory: "www")I tried forcing the other one and the build failed.I also deleted the URL request and added the code to allow access to the parent directory as you mentioned above with the "deletingLastPathComponent"So this is where I am at now. The build succeeds, but I just get a white window and a SIGABRT error.---------------------import UIKitimport WebKitclass ViewController: UIViewController { @IBOutlet weak var loadhtml: WKWebView! override func viewDidLoad() { super.viewDidLoad() let webView = WKWebView() let htmlPath = Bundle.main.path(forResource: "index", ofType: "html", inDirectory: "www") let htmlUrl = URL(fileURLWithPath: htmlPath!) webView.loadFileURL(htmlUrl, allowingReadAccessTo: htmlUrl.deletingLastPathComponent()) view = webView } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } // Do any additional setup after loading the view.}-------------------------Is there something else wrong in the code yet?I have tried so many things I feel lost and don't know what to try next. Thank you again, I really appreciate it.