我正在通过集成WkWebview
在iOS应用程序中集成基于SAML的身份验证。
当我加载URL
(A以获取安全内容)时,它将重定向到另一个试图加载到webview
的(身份验证URL)。
但在webview
中什么也没显示。
import UIKit
import WebKit
class SamlLoginScreenViewController: UIViewController,WKUIDelegate {
@IBOutlet weak var wv_saml: WKWebView!
var webView: WKWebView!
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.uiDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
let myURL = URL(string:"https URL")//it redirect to another //URL e.g. www.login.com( which does not get loaded)
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
}
}
答案 0 :(得分:0)
您可以尝试以下代码-
import UIKit
import WebKit
class ViewController: UIViewController {
@IBOutlet var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let myURL = URL(string:"put Your link here")
let myRequest = URLRequest(url: myURL!)
webView.navigationDelegate = self as? WKNavigationDelegate
webView.load(myRequest)
}
//MARK: Hide status bar
override var prefersStatusBarHidden: Bool{
return true
}
}
答案 1 :(得分:0)
您将零帧设置为webView(webView = WKWebView(frame: .zero, configuration: webConfiguration)
),因此看不到它。尝试为webView设置正确的框架并将其添加为子视图,例如:
webView = WKWebView(frame: view.bounds, configuration: webConfiguration)
view.addSubview(webView)