ios开发多线程篇--异步加载网络图片&&GCD

一.异步加载网络图片

1、ATS

(1)简介

 

从iOS9.0开始,如果按照以前的方式写代码,在访问网络的时候 ,会报以下警告信息:

 

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.

 

原因:iOS9.0引入了新特性(App Transport Security),简称ATS,应用传输安全。

 

新特性要求App内访问的网络必须使用 https 协议。

 

 

(2)解决方案

方法一:

1>  在Info.plist中添加 NSAppTransportSecurity 类型 Dictionary

 

2>  在 NSAppTransportSecurity 下添加 NSAllowsArbitraryLoads 类型 Boolean,设置为 YES

 

方法二:

 

在 info.plist 中 添加

 

        <key>NSAppTransportSecurity</key>

 

         <dict>

 

         <key>NSAllowsArbitraryLoads</key>

 

         <true/>

 

</dict>

 

 

方法三:

代码块

 

2.写代码

 

(1)第一步:定义属性

(2)第二步:初始化控件

 

(3)第三步:下载图片(异步下载图片)

 

3、线程间通信

(1)什么叫做线程间通讯?

    在一个进程中,线程往往不是孤立存在的,多个线程之间需要经常进行通信。

小秘买完烟,必须得回来给班长汇报一下。

(2)线程间通信的体现

1个线程传递数据给另一个线程

 在一个线程中执行完特定任务后,转到另一个线程继续执行任务

(3) 线程间通信常用方法

- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(nullable id)arg waitUntilDone:(BOOL)wait;

- (void)performSelector:(SEL)aSelector onThread:(NSThread *)thr withObject:(nullable id)arg waitUntilDone:(BOOL)wait;

 

 

 

 

 

GCD方法演示   记得还要在plist文件的源文件中加上那上句话(上面内容有)

 

 

posted @ 2016-06-13 23:43  农民农民农民  阅读(1380)  评论(0编辑  收藏  举报