在ios 9中,NSURLSession/NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9802)

在ios 9中,NSURLSession/NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9802),ios,httprequest,nsurlconnection,xcode7.1beta,ios9.1,Ios,Httprequest,Nsurlconnection,Xcode7.1beta,Ios9.1,我试图通过服务器获取图像时出现此错误。 以下是我通过服务器获取图像的代码: -(void)downloadThumbnailWithHeight:(NSInteger)height width:(NSInteger)width callback:(void (^)(UIImage*))callback { NSString* key = [NSString stringWithFormat:@"%ldx%ld", (long)width, (long)height]; UIIma

我试图通过服务器获取图像时出现此错误。
以下是我通过服务器获取图像的代码:

-(void)downloadThumbnailWithHeight:(NSInteger)height width:(NSInteger)width callback:(void (^)(UIImage*))callback {
    NSString* key = [NSString stringWithFormat:@"%ldx%ld", (long)width, (long)height];
    UIImage* __block thumbnail = [_thumbnails objectForKey:key];
    if (thumbnail) { callback(thumbnail); return; }
    HttpRequest* request = [HttpRequest requestWithRelativePath:[NSString stringWithFormat:@"/api/v1/incident/%@/resize?height=%d&width=%d",self.uuid, (int)height, (int)width]];
    [HttpResponse processAsynchronousRequest:request onCompletion:^(HttpResponse* response) {
        dispatch_async(dispatch_get_main_queue(), ^{
            thumbnail = [UIImage imageWithData:response.responseData];
            if (!thumbnail) thumbnail = [UIImage imageNamed:@"gray_thumbnail_background.png"];
            [_thumbnails setObject:thumbnail forKey:key];
            callback(thumbnail);
        });
    }];
}  
在stackoverflow中提出这个问题之前,我已经尝试将其添加到我的info.plist中。这是我的建议:

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>To Find out your location</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>To Find out your location</string>
    <key>CFBundleIdentifier</key>
    <string>com.abc.def</string>
    <key>CFBundleExecutable</key>
    <string>${EXECUTABLE_NAME}</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>CFBundleDevelopmentRegion</key>
    <string>en</string>
    <key>CFBundlePackageType</key>
    <string>BNDL</string>
    <key>CFBundleSignature</key>
    <string>????</string>
</dict>
</plist> 

NSAppTransportSecurity
NSAllowsArbitraryLoads
N位置始终使用说明
找到你的位置
NSLocationWhenUse用途说明
找到你的位置
CbundleIdentifier
com.abc.def
Cbundlexecutable
${EXECUTABLE_NAME}
CbundleInfo字典版本
6
CbundleShortVersionString
1
循环流化床锅炉
1.
CfBundledDevelopmentRegion
EN
CbundlePackageType
BNDL
CFBundleSignature
????
但它仍然不起作用。
当我启动应用程序时,会出现以下错误:

应用程序传输安全已阻止明文HTTP(HTTP://)资源 加载,因为它是不安全的。可以通过配置临时异常 你的应用程序的Info.plist文件

请帮助我,因为我已经花了很多时间来解决这个问题。

提前感谢。

如果您出于某些原因喜欢使用
NSAllowsArbitraryLoads
密钥忽略安全限制,则必须将其放在
NSAppTransportSecurity
字典中,因此只需将dict放在
NSAppTransportSecurity
密钥下即可

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

在plist中添加NSAllowsArbitraryLoads后,您应该尝试删除应用程序并删除Xcode的派生数据文件夹,然后清理并运行项目。。。。!这对我有用。。!我已经尝试过了,但仍然没有其他建议?请检查我的更新问题。我的plist中有什么问题吗?不是“你应该”,而是“你可以暂时作为一个解决办法”。但不应该这样做。“应该”一词意味着这是人们必须做的推荐做法。@MartinH完全同意你的观点,我将编辑我的帖子。这绝对不是一个好的做法。
<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
     <key>yourdomain.com</key>
     <dict>
       <key>NSIncludesSubdomains</key>
       <true/>
       <key>NSExceptionAllowsInsecureHTTPLoads</key>
       <true/>
       <key>NSExceptionMinimumTLSVersion</key>
       <string>TLSv1.2</string>
     </dict>
   </dict>
</dict>