您的位置:首页 > 其它

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

2015-10-06 00:37 337 查看
一、

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

// 
4000
                                    NSLog(@"------%@",imagv.image);

//                                  }];

//    

//    [task resume];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: