Swift iOS 9 NSURLErrorDomain错误-1004 [英] Swift iOS 9 NSURLErrorDomain Error -1004

查看:517
本文介绍了Swift iOS 9 NSURLErrorDomain错误-1004的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS 9和iOS 8中使用Swift 2和Alamofire。在iOS 8中,我对API的所有请求都可以正常工作。在iOS 9中,它们立即失败并显示-1004 NSURLErrorDomain,并显示消息无法连接到服务器。我阅读了Apple对App Transport Security的更改,并已将该条目添加到我的Plist中以禁用它并允许不安全的连接。

I'm using Swift 2 and Alamofire with both iOS 9 and iOS 8. In iOS 8 all my requests to my API work fine. In iOS 9 they immediately fail with a -1004 NSURLErrorDomain with the message "Could not connect to the server.". I read about Apple's change with App Transport Security and already added the entry to my Plist to disable it and allow insecure connections.

我不知道原因是什么对于这个错误...任何帮助都会很棒!

I'm at a loss as to the reason for this error...any help would be great!

推荐答案

在搞乱了大量不同的键和值之后它工作,我终于提出这个使其在iOS9.1中运行:

After messing around with a ton of different keys and values to make it work, I finally have come up with this to make it function in iOS9.1:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSExceptionDomains</key>
    <dict>
        <key>mydomain.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSTemporaryExceptionMinimumTLSVersion</key>
            <string>TLSv1.1</string>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
            <key>NSRequiresCertificateTransparency</key>
            <false/>
        </dict>
    </dict>
</dict>

我添加最后一个 NSRequiresCertificateTransparency 后将其设置为false它有效,所以这可能是最重要的一个。

After I added the last one NSRequiresCertificateTransparency and set that to false it worked, so that's probably the most important one.

这篇关于Swift iOS 9 NSURLErrorDomain错误-1004的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆