App Transport Security Xcode 7测试版6 [英] App Transport Security Xcode 7 beta 6

查看:84
本文介绍了App Transport Security Xcode 7测试版6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究 Xcode 7 beta 6 .我正在尝试向 http://mySubdomain.herokuapp.com

I'm currently working on Xcode 7 beta 6. I'm trying to send a "DELETE" request to http://mySubdomain.herokuapp.com

我收到的错误是:

由于应用传输安全性不安全,因此它阻止了明文HTTP(http://)资源加载.可以通过应用程序的Info.plist文件配置临时例外.
进行API调用时出错:Error Domain = NSURLErrorDomain代码= -1022无法加载资源,因为应用程序传输安全性"策略要求使用安全连接.
NSLocalizedDescription =无法加载资源,因为应用传输安全策略需要使用安全连接.,NSUnderlyingError = 0x796f7ef0 {Error Domain = kCFErrorDomainCFNetwork Code = -1022(null)"}}

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.
Error making API call: Error Domain=NSURLErrorDomain Code=-1022 The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.
NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection., NSUnderlyingError=0x796f7ef0 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "(null)"}}

在我的实际API调用中,我放置了"https"而不是"http",并且该设置实际上适用于我的POST请求.但是DELETE请求会引发上述错误.

In my actual API call I put "https" instead of "http" and that actually worked for my POST requests. But the DELETE request throws the above error.

我在这里看到了涉及pList文件的解决方案,但是没有一个对我有用.我在下面列出了我的尝试.

I've seen solutions on here that involve the pList file, but none of them have worked for me. I've listed my attempts below.

第一次尝试:

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

第二次尝试:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>herokuapp.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
            <key>NSExceptionMinimumTLSVersion</key>
            <string>TLSv1.2</string>
            <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
            <key>NSThirdPartyExceptionMinimumTLSVersion</key>
            <string>TLSv1.2</string>
            <key>NSRequiresCertificateTransparency</key>
            <false/>
        </dict>
    </dict>
</dict>

最后,我什至将所有这些临时键都放入这样:

And finally, I even put all these temporary keys in like so:

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>herokuapp.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSTemporaryIncludesSubdomains</key>
                <true/>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <false/>
                <key>NSTemporaryExceptionRequiresForwardSecrecy</key>
                <false/>
                <key>NSExceptionMinimumTLSVersion</key>
                <string>TLSv1.2</string>
                <key>NSTemporaryExceptionMinimumTLSVersion</key>
                <string>TLSv1.2</string>
                <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSTemporaryThirdPartyExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
                <false/>
                <key>NSTemporaryThirdPartyExceptionRequiresForwardSecrecy</key>
                <false/>
                <key>NSThirdPartyExceptionMinimumTLSVersion</key>
                <string>TLSv1.2</string>
                <key>NSTemporaryThirdPartyExceptionMinimumTLSVersion</key>
                <string>TLSv1.2</string>
                <key>NSRequiresCertificateTransparency</key>
                <false/>
                <key>NSTemporaryRequiresCertificateTransparency</key>
                <false/>
            </dict>
        </dict>
    </dict>

一切都没有运气!我总是得到同样的错误. DELETE请求的格式正确,因为当我从Postman手动进行处理时,得到了所需的结果.

All with no luck! I always get the same error. The DELETE request is formatted correctly because when I manually do it from Postman, I get the desired result.

这是我实际的API调用方法的外观,以防万一在这里出现问题:

Here is what my actual API call method looks like, just in case there could be an issue here:

class func makeDELETEALLRequest(completion: (error:Bool) -> Void) {
        let session = NSURLSession.sharedSession()
        let url = NSURL(string:"https://mysubdomain.herokuapp.com/42kh24kh2kj2g24/clean")
        let request = NSMutableURLRequest(URL: url!)
        request.HTTPMethod = "DELETE"

        let task = session.dataTaskWithRequest(request) { (data, response, error) -> Void in

            if (error != nil) {
                print("Error making API call: \(error!)")
                completion(error: true)
            } else {
                let HTTPResponse = response as! NSHTTPURLResponse
                let statusCode = HTTPResponse.statusCode
                if (statusCode == 200){
                    print("Successfully deleted!")
                    completion(error: false)
                } else {
                    print("Different status code: \(statusCode)")
                    completion(error: true)
                }
            }
        }
        task.resume()
    }

我再次使用 Xcode 7 beta 6 .

关于我选择的答案 我选择正确的答案对我来说是正确的,因为我对项目中的错误pList文件进行了所有这些更改,并且该答案是唯一解决可能性的方法.其他答案提供的解决方案没有错,因此遇到此问题的其他任何人都应该尝试一下,因为它们是有效的.希望这对遇到类似问题的人有所帮助.

ABOUT MY SELECTED ANSWER The answer I selected as correct was right for me because I made all these changes to the wrong pList file in my project and that answer was the only one that addressed the possibility. The solutions offered by the other answers are not wrong, so any other people experiencing this issue should give them a try, since they are valid. I hope this helps anyone having similar issues.

推荐答案

在升级到xCode 7.0后,我也无法覆盖App Transport Security,并尝试了无济于事的同类解决方案.走了一段时间之后,我注意到我已经对"MyAppName测试"的支持文件"下的Info.plist进行了更改,而不是项目本身中的内容.我项目中的Supporting Files文件夹没有展开,因此我什至没有注意到其中的Info.plist.

I, too, had trouble overriding App Transport Security after upgrading to xCode 7.0, and tried the same kinds of solutions you have to no avail. After walking away from it for awhile, I noticed that I had made the changes to the Info.plist under Supporting Files of "MyAppName Tests" rather than the one in the project itself. The Supporting Files folder in my project wasn't expanded, so I hadn't even noticed the Info.plist in it.

我敢肯定,这是典型的业余错误,但在Project Navigator中只有两行之隔,这让我感到沮丧,直到我注意到了区别.以为我会提到它,以防万一您遇到同样的问题.

Typical amateur mistake, I'm sure, but they're only a couple of lines apart in the Project Navigator and it had me frustrated until I noticed the distinction. Thought I'd mention it in case you're having the same problem.

这篇关于App Transport Security Xcode 7测试版6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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