zoukankan      html  css  js  c++  java
  • Xcode 7 ATS设置

    这两天研究SDWebimage库,在xode 7上运行过程中遇到了些问题,创建的新项目由于使用到了https的图片URL,运行后,怎么都不出现图片,发送请求时,报下面的错: 

    “App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app’s Info.plist file”

    经过搜索stackoverflow查询相关问题发现,iOS9新特性要求App内访问网络请求要采用HTTPS协议,无论url是http的还是https的。通过进行如下设置即可:

    1. 在Info.plist中添加 NSAppTransportSecurity 类型 Dictionary ;
    2. 在 NSAppTransportSecurity 下添加 NSAllowsArbitraryLoads 类型Boolean ,值设为 YES;

    然后尝试了SDWebimage不同的图片加载方法,均成功展示。后面可以正常研究图片缓存的实现了。

    /**

         *  Using SDWebimage

         */

      NSURL *imgURL = [NSURL URLWithString:@"http://www.sogou.com/images/logo/new/sogou.png"];

     

        // Using UIImageView+WebCache category

        [imageView sd_setImageWithURL:imgURL

                     placeholderImage:[UIImage imageNamed:@"default_pic"]];

        

        // Using blocks

        [imageView sd_setImageWithURL:imgURL

                     placeholderImage:[UIImage imageNamed:@"default_pic"]

                            completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {

                                

                            }];

        

        // Using SDWebImageManager

        SDWebImageManager *manager = [SDWebImageManager sharedManager];

        [manager downloadImageWithURL:imgURL

                              options:0

                             progress:^(NSInteger receivedSize, NSInteger expectedSize) {

                                 // progression tracking code

                             }

                            completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {

                                if (image) {

                                    // do something with image

                                    [imageView setImage:image];

                                }

                            }];

        

        // Using Asynchronous Image Downloader Independently

        SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader];

        [downloader downloadImageWithURL:imgURL

                                 options:0

                                progress:^(NSInteger receivedSize, NSInteger expectedSize) {

                                    // progression tracking code

                                }

                               completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {

                                   if (image && finished) {

                                       // do something with image

                                       [imageView setImage:image];

                                   }

                               }];

  • 相关阅读:
    mysql自动补齐
    重置oracle 11G的system、sys密码《亲测》
    细说业务逻辑(前篇)<转>
    当我们把这么一个“狭义的概念”与“这个概念本身”等同起来时,误会、迷茫、困惑、不屑就出现了。
    设计模式就三个准则
    面向对象编程(OOP)的三大特点
    在计算机中,“透明”一词的理解。
    关于ArrayList中添加对象的一个有趣问题~~~~
    MyEclipse 代码自动提示功能失效 提示No Default Proposals 或 no completions available 的解决方法
    面向对象的三大基本特征
  • 原文地址:https://www.cnblogs.com/ranger-jlu/p/4920428.html
Copyright © 2011-2022 走看看