美文网首页
NSData的dataWithContentsOfURL调用后为

NSData的dataWithContentsOfURL调用后为

作者: c5550ea746f8 | 来源:发表于2018-01-15 15:22 被阅读762次

                NSString *URL = [IMAGE_ADD_HEADER(urlStr) stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

                NSURL *url = [NSURL URLWithString:URL];

               UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];//[NSData dataWithContentsOfURL:url]返回值为空;

//                NSData *data = UIImageJPEGRepresentation(image, 0.5);

有说在info.plist文件里添加Key:App Transport Security Settings —— Allow Arbitrary Loads 为YES 就可以了,但是这样设置了还是没好,所以换了个方式:

NSString *URL = [IMAGE_ADD_HEADER(urlStr) stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

                NSURL *url = [NSURL URLWithString:URL];

                NSData* data = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:url] returningResponse:NULL error:NULL];

相关文章

网友评论

      本文标题:NSData的dataWithContentsOfURL调用后为

      本文链接:https://www.haomeiwen.com/subject/vvfdoxtx.html