【发布时间】:2015-12-29 15:15:48
【问题描述】:
当我尝试通过服务器获取图像时出现此错误。
这是我通过服务器获取图像的代码:
-(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>
但它仍然无法正常工作。
当我启动应用程序时,它给了我以下错误:
App Transport Security 已阻止明文 HTTP (http://) 资源 加载,因为它不安全。可以通过以下方式配置临时异常 您应用的 Info.plist 文件。
请帮助我,因为我已经花了两个时间来解决这个问题。
提前致谢。
【问题讨论】:
-
在 plist 中添加 NSAllowsArbitraryLoads 后,您应该尝试删除应用程序并删除 Xcode 的派生数据文件夹并清理并运行项目....!它对我有用..!
标签: ios httprequest nsurlconnection xcode7.1beta ios9.1