ios - Webview 不适用于 iOS9

标签 ios swift webview ios9

<分区>

我创建的应用程序不适用于 iOS 9。

import UIKit

    class WebViewController: UIViewController, UIWebViewDelegate {

        @IBOutlet var webView: UIWebView!
        override func viewDidLoad()
        {
            super.viewDidLoad()
            // Do any additional setup after loading the view.

            let requestURL = NSURL(string:"http://stackoverflow.com")
            let request = NSURLRequest(URL: requestURL!)
            webView.loadRequest(request)

            webView.delegate = self

        }

        override func didReceiveMemoryWarning()
        {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }

        func webViewDidStartLoad(webView: UIWebView)
        {
            print("Load started")
            UIApplication.sharedApplication().networkActivityIndicatorVisible = true
        }
        func webViewDidFinishLoad(webView: UIWebView)
        {
            print("Load finished")
            UIApplication .sharedApplication().networkActivityIndicatorVisible = false

        }
        func webView(webView: UIWebView, didFailLoadWithError error: NSError?)
        {
            print("Error = ", error)
        }
        func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool
        {
            print("URl ", request.URL?.absoluteString)
            return true
        }
    }

显示此消息。

2015-10-20 14:46:29.976 WebViewDemo[2802:84627] Loading URL :https://stackoverflow.com/ 2015-10-20 14:46:30.041 WebViewDemo[2802:84745] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file. 2015-10-20 14:46:30.160 WebViewDemo[2802:84627] Failed to load with error :Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSUnderlyingError=0x7fedabe113b0 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSErrorFailingURLStringKey=https://stackoverflow.com/, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection., NSErrorFailingURLKey=https://stackoverflow.com/}}, NSErrorFailingURLStringKey=https://stackoverflow.com/, NSErrorFailingURLKey=https://stackoverflow.com/, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.}

最佳答案

你必须在你的.plist 文件中添加这个

  1. 添加一个NSAppTransportSecurity:字典。
  2. 添加名为 NSAllowsArbitraryLoads 的子项作为 Boolean : YES

enter image description here

希望这对你有帮助。

关于ios - Webview 不适用于 iOS9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33233243/

相关文章:

ios - 将 UILabel 掩码添加到 UIVisualEffectView

ios - FMOD 在 iOS 平台上比苹果的音频 API 有什么好处?

UITableView 布局在推送 segue 和返回时搞砸了。 (iOS 8、Xcode beta 5、Swift)

swift - 尝试在 Firestore 上进行另一个查询时出错

iphone - 在多台计算机上为 iOS 开发,在单个设备上测试,建议?

swift - AdMob 显示测试广告但不显示真实广告 Swift/SwiftUI

java - 在另一个 Web View 控件中打开超链接

android - FlipAnimation 在 4.4.3 中导致问题

android webview错误找不到页面

iOS Storyboard