iOS developing multi-threaded article--Loading network pictures asynchronously

Source: Internet
Author: User

I. Asynchronously loading a network picture

1. ATS(1) Introduction

Starting with iOS9.0, if you write the code in the previous way, the following warning message is reported when accessing the network:

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.

Reason: iOS9.0 introduced a new feature (app Transport Security), referred to as ATS, and applied transport safety.

The new feature requires that the network access within the app must use the HTTPS protocol.

(2) Solutions

Method One:

1> add nsapptransportsecurity type in Info.plist Dictionary

2> Add nsallowsarbitraryloads type Boolean under Nsapptransportsecurity, set to YES

Method Two:

Add in Info.plist

<key>NSAppTransportSecurity</key>

<dict>

<key>NSAllowsArbitraryLoads</key>

<true/>

</dict>

Method Three:

code block

2. Write code

(1) First step: defining attributes

(2) Step two: Initialize the control

(3) Step three: Download images (download images asynchronously)

3. Communication between threads

(1) What is called inter-thread communication?

In a process, threads often do not exist in isolation, and there is a need for frequent communication between multiple threads.

The small secret buys the smoke, must have to return to the Monitor report.

(2) The embodiment of inter-thread communication

1 Threads passing data to another thread

After performing a specific task in one thread, go to another thread to continue the task

(3) Common methods of inter-thread communication

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

iOS developing multi-threaded article--Loading network pictures asynchronously

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.