Xcode版升级为7.0时,原来版本的工程图片数据请求需要设置

一、


XCODE版升级为7.0

就要在 :1、工程中的 Info.plist中添加 NSAppTransportSecurity 其类型为Dictionary

2、在NSAppTransportSecurity下添加NSAllowsArbitraryLoads类型Boolean,其值设为YES



二、请求图片数据时可将 方法 viewDidLoad1 以 方法 viewDidLoad2 代替

- (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];

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值