【问题标题】:SSL error has occured发生 SSL 错误
【发布时间】:2018-06-18 08:04:49
【问题描述】:

我在 iTunes 上上传了我的应用程序,它也是实时的,但在某些设备上(主要是 iPhone7)。将 Xcode 或 ios 版本升级到 11.4 后,出现 SSL 连接错误
在 iphone 6s 或 ipad 上工作正常,但在客户端 iphone 7 上发生此错误附有错误的屏幕截图,我无法理解发生了什么,需要更改什么。

我已经在 info plist 中添加了这段代码

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>yourdomain.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
                <false/>
            </dict>
        </dict>
    </dict>

我们还会检查服务器证书是否有效。

【问题讨论】:

    标签: objective-c iphone ios11


    【解决方案1】:

    首先检查您的端口是否有 SSL 并更正用于 SSL 固定的证书

    检查 SSL 代码

     - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
          return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
        }
    
        - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
          if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
            if ([trustedHosts containsObject:challenge.protectionSpace.host])
              [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
    
          [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
        }
    

    【讨论】:

      猜你喜欢
      • 2015-12-28
      • 2016-08-02
      • 2017-05-01
      • 2019-12-12
      • 1970-01-01
      • 1970-01-01
      • 2015-11-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多