ios – Navigation Bar No Longer Exhibiting from Storyboard in Controller – Swift (Up to date View Controller To Deal with Opening Hyperlinks WEBVIEW)


With the next code, I used to be in a position to show my Navigation Bar construct on Storyboard, nevertheless, andy URL hyperlinks wouldn’t open and have been lifeless. I discovered my ViewController wanted a method to deal with utilizing a call handler. (SEE WHAT DID I TRY SECTION)

import UIKit
import WebKit

class SecondViewController: UIViewController {

        @IBOutlet weak var webViewTwo: WKWebView!
        override func viewDidLoad() {
            tremendous.viewDidLoad()
            

            
            let url = URL(string: "https://on.sprintful.com/dr-clutter-junk")
            webViewTwo.load(URLRequest(url: url!))
                  
        }
        
        override var preferredStatusBarStyle: UIStatusBarStyle {
            return .lightContent
        }
 

 

}

enter picture description right here

SECTION: WHAT DID I TRY

With the next code, the hyperlinks work however the Nav Bar from StoryBoard doesn’t show.
I imagine the is the IB Outlet reference is the difficulty. After I go to edit the

“func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler:” and alter it to “func webViewTwo(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler:” the nav bar wont present and hyperlinks don’t work.

import UIKit
import WebKit

class SecondViewController: UIViewController, WKNavigationDelegate {
@IBOutlet var webViewTwo: WKWebView!

override func loadView() {
    webViewTwo = WKWebView()
    view = webViewTwo
    let url = URL(string: "https://calendly.com/drclutterjunk")!
    webViewTwo.load(URLRequest(url: url))
    webViewTwo.allowsBackForwardNavigationGestures = true
    webViewTwo.navigationDelegate = self
    
    
}
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
            if navigationAction.navigationType == .linkActivated  {
                if let url = navigationAction.request.url,
                let host = url.host, host.hasPrefix("dttps://calendly.com") !=
                    UIApplication.shared.canOpenURL(url) {
                        UIApplication.shared.open(url)
                        decisionHandler(.cancel)
                } else {
                    // Open in internet view
                    decisionHandler(.enable)
                }
            } else {
                // different navigation sort, corresponding to reload, again or ahead buttons
                decisionHandler(.enable)
            }
        }

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .darkContent
}


}

enter picture description right here

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles