从 url 检索 jpg 图像返回 nil。但是,从 url 检索 png 图像效果很好

Jam*_*obo -1 iphone xcode objective-c ipad ios

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

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;
    });
});
Run Code Online (Sandbox Code Playgroud)

但是,如果我使用以下代码,我将在我的 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;
    });
});
Run Code Online (Sandbox Code Playgroud)

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

Abd*_*ish 5

您的第一个图像是HTTP您需要将 App Transport Security添加到列表中的 yes

在此输入图像描述

 <key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
Run Code Online (Sandbox Code Playgroud)