xcode7 iOS9 HTTP 不能正常使用的解决办法

分享 · xiaodu · 发布于 2 年前 · 4350 次阅读

升级Xcode7后发现之前写的http接口访问不了,查了发现 iOS9引入了新特性App Transport Security (ATS),新特性要求App内访问的网络必须使用HTTPS协议。详情:App Transport Security (ATS)

App Transport Security (ATS) enforces best practices in the secure connections between an app and its back end. ATS prevents accidental disclosure, provides secure default behavior, and is easy to adopt; it is also on by default in iOS 9 and OS X v10.11. You should adopt ATS as soon as possible, regardless of whether you’re creating a new app or updating an existing one.

If you’re developing a new app, you should use HTTPS exclusively. If you have an existing app, you should use HTTPS as much as you can right now, and create a plan for migrating the rest of your app as soon as possible. In addition, your communication through higher-level APIs needs to be encrypted using TLS version 1.2 with forward secrecy. If you try to make a connection that doesn't follow this requirement, an error is thrown. If your app needs to make a request to an insecure domain, you have to specify this domain in your app's Info.plist file.


  1. 升级服务端成Https
  2. 修改Info.plist






2.按照上面提到的方式添加信息,正确的修改会看到下图这个样子,注意类型NSAppTransportSecurityDictionaryNSAllowsArbitraryLoadsBoolean,复制粘贴的时候,不要多了空格,segment fault 页面上直接复制,经常会多一个出空格!





2.App Transport Security (ATS)

共收到 2 条回复
wangyongxin546 · #1 · 2 年前

更新完EI Capitan 10.11操作系统和XCODE Version 7.0.1 (7A1001) 后模拟器无法加载http://图片

@IBOutlet weak var iv: UIImageView!
@IBAction func test(sender: UIButton) {
    let url = "" + "/register/captcha.jhtml?captchaId="
    let nsd = NSData(contentsOfURL:NSURL(string: url)!)

    if nsd == nil {
        print("net error")
    let img = UIImage(data: nsd!)
    iv.image = img
suzee · #2 · 2 年前