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];
网友评论