try 在iOS9上运行我现有的应用程序,但在使用AFURLSessionManager时失败.

__block NSURLSessionDataTask *task = [self.sessionManager dataTaskWithRequest:request completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {
    if (error) {

    } else {

    }
}];

[task resume];

我得到以下错误:

Error Domain=NSURLErrorDomain Code=-999 "cancelled.

另请参阅以下日志(log):

 NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9824
 CFNetwork SSLHandshake failed (-9824)

Update:

推荐答案

找到解决方案:

在iOS9中,ATS在网络通话期间实施最佳实践,包括使用HTTPS.

From Apple documentation:

ATS prevents accidental disclosure, provides secure default behavior, and is easy to adopt. 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.

在测试版1中,目前没有办法在info.plist中定义这一点.解决方案是手动添加:

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

在此处输入图像描述

Update1: This is a temporary workaround until you're ready to adopt iOS9 ATS support.

Update2:有关更多详细信息,请参阅以下链接: http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/

如果您try 连接到仅具有TLS 1.0的主机(YOURHOST.COM),则为Update3:

将这些添加到应用程序的信息中.普利斯特

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>YOURHOST.COM</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSTemporaryExceptionMinimumTLSVersion</key>
            <string>1.0</string>
            <key>NSTemporaryExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
    </dict>
</dict>

Ios相关问答推荐

崩溃到初始化react -带网页的原生iOS应用程序

SwiftUI拖动手势和内容拖动时的奇怪行为( skip /卡顿)

在Android和iOS上从后台恢复应用程序后,inappwebview上出现白屏?

在带有可编码的SWIFT5中,可以轻松处理以美元符号开头的JSON密钥,例如$DATE";

Xcode 15模拟器用x86_64编译

在 Swift 项目中使用情节提要加载 obj-c 文件

Swift/iOS:泛型错误:协议需要嵌套类型V;你想添加它吗?

Flutter 构建 ios 失败:运行 pod 安装时出错

使用 AVCaptureDeviceTypeBuiltInTripleCamera 时 Select 合适的相机进行条码扫描

SwiftUI Disclosure Group 文本对齐

搜索在 ios xamarin.forms 中不起作用

我可以使用同一个 Firebase 应用将多个 Flutter 应用添加到一个 Firebase 数据库吗?

在 UICollectionView 上从右到左对齐

Xcode 8,iOS 10 -为进程启动 WebFilter 日志(log)记录

如何告诉 SwiftUI 视图绑定到嵌套的 ObservableObjects

NSFetchedResultsController 由字符串的第一个字母创建的部分

无法将NSTaggedPointerString类型的值转换为NSNumber

故事板中的 colored颜色 与 UIColor 不匹配

Objective-C 将 NSDate 设置为当前 UTC

找不到开发者磁盘映像