Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从url检索jpg图像返回nil。但是,从url检索png图像效果很好_Ios_Objective C_Iphone_Xcode_Ipad - Fatal编程技术网

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

Ios 从url检索jpg图像返回nil。但是,从url检索png图像效果很好,ios,objective-c,iphone,xcode,ipad,Ios,Objective C,Iphone,Xcode,Ipad,如果我使用下面的代码,数据将为零 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.j

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

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您需要在列表中的“是”中添加应用程序传输安全性

NSAppTransportSecurity
NSAllowsArbitraryLoads

您的第一张图像是HTTP您需要将应用程序传输安全添加到列表中的“是”

NSAppTransportSecurity
NSAllowsArbitraryLoads

尝试加载http URL时,您是否在控制台中看到任何消息?首先在plist中添加ATS,检查图像URL是否有多余空间。然后调用服务当尝试加载http URL时,您是否在控制台中看到任何消息?首先在plist中添加ATS,检查图像URL必须有额外的空间。然后打电话给服务部,非常感谢@Abdelahad Darwish。现在一切都很好,非常感谢@Abdelahad Darwish。现在一切都好了
 <key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>