-
Re: Help with links in WebViews.
eskimo Nov 1, 2016 3:21 AM (in response to iFunnyVlogger Dev)Unless you have specific reasons to stick with UIWebView, I strongly recommend you adopt the more modern WKWebView.
In WKWebView you can set a navigation delegate that the web view calls as part of the navigation process. Two of those delegate callbacks —
webView(_:decidePolicyForNavigationAction:decisionHandler:)
andwebView(_:decidePolicyForNavigationResponse:decisionHandler:)
— allow you to override navigation policy. You can implement one of these to cancel the navigation and then open the URL in Safari by UIApplication’sopenURL(_:)
method.Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardwarelet myEmail = "eskimo" + "1" + "@apple.com"
-
Re: Help with links in WebViews.
iFunnyVlogger Dev Nov 1, 2016 5:39 AM (in response to eskimo)Ok, is there any way to do it with a webview? I am very, very new to coding, and I'm still very much learning.
-
Re: Help with links in WebViews.
eskimo Nov 2, 2016 3:31 AM (in response to iFunnyVlogger Dev)UIWebView has a delegate that has similar, although less capable, facilities.
However, if you’re just starting out with web views, you should use WKWebView; WKWebView is the future of web views, while UIWebView is very much the past.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardwarelet myEmail = "eskimo" + "1" + "@apple.com"
-
Re: Help with links in WebViews.
iFunnyVlogger Dev Nov 10, 2016 2:33 PM (in response to eskimo)Ok, I'll use WKWebView, what is the code I need to add?
-
Re: Help with links in WebViews.
eskimo Nov 11, 2016 3:32 AM (in response to iFunnyVlogger Dev)what is the code I need to add?
To do what? Set up a web view? Or catch a link?
Here’s some code from my WKWebView test app that sets up the web view.
class WKWebViewController : UIViewController, WKNavigationDelegate { var webView: WKWebView { return self.view as! WKWebView } override func loadView() { let config = WKWebViewConfiguration() let webView = WKWebView(frame: CGRect.zero, configuration: config) webView.navigationDelegate = self self.view = webView } … }
I don’t have the code handy for catching link requests, but it should just be a matter of implementing the delegate methods I described above.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardwarelet myEmail = "eskimo" + "1" + "@apple.com"
-
-
-
-