我嘗試通過服務器獲取圖像時出現此錯誤。
這裏是我的代碼,通過服務器上獲取圖像:ios 9中的NSURLSession/NSURLConnection HTTP加載失敗(kCFStreamErrorDomainSSL,-9802)
-(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);
});
}];
}
之前,我在計算器問這個問題,我已經嘗試在我的info.plist中添加此。這是我的plsit:
<?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>
但它仍然無法正常工作。
IT給我下面的錯誤,當我啓動應用程序:
應用傳輸安全性已阻止明文HTTP(HTTP://)資源 負載,因爲它是不安全的。臨時例外可以通過 您的應用程序的Info.plist文件進行配置。
請幫助我,因爲我已經花了很多時間來解決這個問題。
在此先感謝。
在plist中加入NSAllowsArbitraryLoads後,你應該嘗試刪除應用程序,並刪除Xcode中導出的數據文件夾,乾淨,運行項目... 。!它爲我工作..! –
不工作的傢伙。 –