设置webview委托后无法加载WebView

时间:2017-08-09 12:13:59

标签: ios swift uiwebview

class SSOViewController: UIViewController, UIWebViewDelegate
{

@IBOutlet weak var ssoWebView: UIWebView!
var activityData : ActivityData!

var ssoUrl: String!

override func viewDidLoad()
{
    super.viewDidLoad()
    activityData = ActivityData()
    ssoWebView.delegate = self
    ssoWebView.loadRequest(URLRequest(url: URL(string: ssoUrl)!) )
}

override func didReceiveMemoryWarning()
{
    super.didReceiveMemoryWarning()
}

func webViewDidStartLoad(_ webView: UIWebView)
{
    NVActivityIndicatorView.DEFAULT_BLOCKER_SIZE = CGSize(width: 45, height: 45)
    NVActivityIndicatorPresenter.sharedInstance.startAnimating(activityData)
}

func webViewDidFinishLoad(_ webView: UIWebView)
{
    //NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
}

func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool
{
    print(request.mainDocumentURL ?? "no url")
    return false
}

}

这就是我将内容加载到webview和webViewDidStartLoad方法以及webViewDidFinishLoad方法中添加的活动指标。这两种方法也没有启动。

1 个答案:

答案 0 :(得分:0)

检查info.plist中的传输安全性

  1. 打开info.plist文件

  2. 将名为NSAppTransportSecurity的密钥添加为字典

  3. 将名为NSAllowsArbitraryLoads的子项添加为布尔值,并将其值设置为YES

  4. enter image description here