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>