gpt4 book ai didi

ios - 从 url 检索 jpg 图像返回 nil。但是,从 url 检索 png 图像工作正常

转载 作者:行者123 更新时间:2023-11-28 18:48:56 25 4
gpt4 key购买 nike

如果我使用下面的代码,数据将为零

dispatch_async(dispatch_get_global_queue(0,0), ^{
UIImage *img = [[UIImage alloc] init];
NSData * data = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:@"http://www.manipalgrocer.com/image/catalog/BANNER/sweets.jpg"]];
img = [UIImage imageWithData: data];
dispatch_async(dispatch_get_main_queue(), ^{
menuCell.imgMenu.image = img;
});
});

但是,如果我使用以下代码,我将在我的 menuCell 中获取图像

dispatch_async(dispatch_get_global_queue(0,0), ^{
UIImage *img = [[UIImage alloc] init];
NSData * data = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:@"https://www.fooodzapp.com/image/catalog/JUST%20CHILL/Justchill%20(1).png"]];
img = [UIImage imageWithData: data];
dispatch_async(dispatch_get_main_queue(), ^{
menuCell.imgMenu.image = img;
});
});

如果有人知道如何解决这个问题,请回复。提前致谢

最佳答案

您的第一张图片是HTTP您需要将App Transport Security添加到列表中的是

enter image description here

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

关于ios - 从 url 检索 jpg 图像返回 nil。但是,从 url 检索 png 图像工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45845089/

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