一、
在XCODE版升级为7.0了
就要在 :1、工程中的 Info.plist中添加 NSAppTransportSecurity 其类型为Dictionary。
2、在NSAppTransportSecurity下添加NSAllowsArbitraryLoads类型Boolean,其值设为YES
- (void)viewDidLoad1 {
[superviewDidLoad];
self.view.backgroundColor = [UIColorgrayColor];
NSURL *url = [NSURLURLWithString:@"https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=903634168,884117676&fm=116&gp=0.jpg"];
NSURLRequest *request = [NSURLRequestrequestWithURL:url];
NSURLResponse *response;
NSData *data =[NSURLConnectionsendSynchronousRequest:requestreturningResponse:&responseerror:nil];
UIImageView *imagv = [[UIImageViewalloc]initWithFrame:CGRectMake(100,200,100, 100)];
imagv.backgroundColor = [UIColorredColor];
imagv.image = [UIImageimageWithData:data];
[self.viewaddSubview:imagv];
改为一下
- (void)viewDidLoad2 {
// NSURLRequest *request1 = [NSURLRequest requestWithURL:URL];
//
// NSURLSession *session = [NSURLSession sharedSession];
//
// NSURLSessionDataTask *task = [session dataTaskWithRequest:request1
// completionHandler:
// ^(NSData *data, NSURLResponse *response, NSError *error) {
// UIImageView *imagv = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
// imagv.backgroundColor = [UIColor redColor];
// [self.view addSubview:imagv];
// imagv.image = [UIImage imageWithData:data];
// NSLog(@"------%@",imagv.image);
// }];
//
// [task resume];
}