gpt4 book ai didi

ios - 错误 : Get Image from URL

转载 作者:行者123 更新时间:2023-11-28 17:59:00 25 4
gpt4 key购买 nike

我有 2 个图像 URL,当我将它们添加到浏览器时,2 个图像 URL 显示图像。当我从 URL 获取图像并将其放入数组时出现错误。

案例 1:我使用 stringURL1,OK enter image description here

案例 2:我使用 stringURL2,然后,如您所见,它崩溃了! enter image description here

我的代码:

- (void)viewDidLoad {
[super viewDidLoad];
NSString* stringURL1 = @"https://www.wonderplugin.com/wp-content/uploads/2014/06/wordpress-lightbox-gallery.png";

NSString* stringURL2 = @"http://cdn3.vox-cdn.com/uploads/chorus_asset/file/917470/iphone-6-travel-photo-review-mann-header.0.jpg";

NSURL *url = [NSURL URLWithString:stringURL1];

NSData* imageData = [[NSData alloc]initWithContentsOfURL:url];

UIImage* image = [[UIImage alloc] initWithData:imageData];

NSArray *arrayData = @[@"1", @"2", image];

NSLog(@"%@",arrayData);


}

你能为我解释一下这个错误吗?

最佳答案

这是因为iOS9造成的。 iOS9 需要由 https 而非 http 提供的安全连接和足够强大的证书来支持它。

有两种方法可以实现这一点。

要么您需要访问 https 端点而不是 http,要么修改您的 .plist 文件以绕过它们。

在您的 .plist 中有一个名为 NSAppTransportSecurity 的字典,它下面有一个 NSAllowsArbitraryLoads bool 值。将其更改为 YES 将让您绕过它们。

plist example

请记住,绕过是一种临时解决方案,可能会给您带来安全问题。

根据评论编辑

它正在崩溃,因为连接从未发生过。图像保持为 nil,而您最终尝试将 nil 对象放入数组中,这导致了崩溃。

关于ios - 错误 : Get Image from URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33077765/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com