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文件的源文件中加上那上句話(上面內容有)
?
?
轉載于:https://www.cnblogs.com/huangfang1314/p/5582494.html
總結
以上是生活随笔為你收集整理的ios开发多线程篇--异步加载网络图片GCD的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CSS:给 input 中 type=t
- 下一篇: Oracle dump 分析second