uiwebview 不适用于 Swift 2.0

uiwebview is not working for Swift 2.0

我用于 Xcode 6.4 打开 uiwebview 的代码在启动模拟器时没有加载 Xcode 7。

class ViewController: UIViewController {

@IBOutlet var webLaundry: UIWebView!


func loadWebPage(){
    let theURL = "http://www.google.com"
    let theRequestURL = NSURL (string: theURL)
    let theRequest = NSURLRequest (URL: theRequestURL!)
    webLaundry.loadRequest(theRequest)
}

override func viewDidLoad() {
    super.viewDidLoad()
    loadWebPage()
    // Do any additional setup after loading the view, typically from a nib.
}

我应该更改什么来解决这个问题?

这是苹果的新安全要求。 iOS 9 中的应用程序传输安全性。

您需要做的是:

  1. in xcode 7、在你的项目中,找到“Info.plist”,右击,以“源代码”方式打开。

  2. 在最后和

  3. 之间添加单词

<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key><true/> </dict>

  1. 运行 你的项目
  2. Source