热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Webview不支持iOS9[duplicate]-WebviewnotworkingwithiOS9[duplicate]

Thisquestionalreadyhasananswerhere:这个问题已经有了答案:Transportsecurityhasblockedacl

This question already has an answer here:

这个问题已经有了答案:

  • Transport security has blocked a cleartext HTTP 23 answers
  • 传输安全阻塞了一个明文HTTP 23的答案。

I had created app which is not working with iOS 9.

我创建了一个不支持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
        }
    }

Showing this message.

显示此消息。

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.}

WebViewDemo[2802:84627]加载URL:https://stackoverflow.com/ 2015-10-2014:46:30.041 WebViewDemo[2802:84745]由于不安全,App传输安全性阻止了cleartext HTTP (http://)资源加载。临时异常可以通过应用程序的信息进行配置。plist文件。WebViewDemo[2802:84627]加载失败:error Domain=NSURLErrorDomain Code=-1022“无法加载资源,因为应用传输安全策略需要使用安全连接。”UserInfo={NSUnderlyingError=0x7fedabe113b0 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "无法加载资源,因为应用程序传输安全策略需要使用安全连接。"UserInfo={NSErrorFailingURLStringKey=https://stackoverflow.com/, NSLocalizedDescription=无法加载资源,因为应用传输安全策略需要使用安全连接。NSErrorFailingURLKey=https://stackoverflow.com/}, nserfailingurlstringkey =https://stackoverflow.com/, nserfailingurlkey =https://stackoverflow.com/, NSLocalizedDescription=资源不能被加载,因为应用传输安全策略需要使用安全连接。

2 个解决方案

#1


2  

You have to add this in your .plist file

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

  1. Add a NSAppTransportSecurity : Dictionary.
  2. 添加一个NSAppTransportSecurity: Dictionary。
  3. Add Subkey named : NSAllowsArbitraryLoads as Boolean : YES
  4. 添加名为:nsallowsarbitraryload的子键作为布尔值:YES

enter image description here

Hopefully this will help you.

希望这能对你有所帮助。

#2


0  

Set the NSAllowsArbitraryLoads key to YES under NSAppTransportSecurity dictionary in your .plist file. If NSAppTransportSecurity not exist manually write it.

在.plist文件中,在NSAppTransportSecurity字典中将nsallowsarbitraryload键设置为YES。如果NSAppTransportSecurity不存在,手动写它。

enter image description here


推荐阅读
author-avatar
天蝎樱花西街1992
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有