URLSession sessionWithConfiguration:config delegate:self delegateQueue:[NSOperationQueue mainQueue]

來源:互聯網
上載者:User

標籤:

NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];

        

        /**

         參數

         1. 配置

         2. 代理

         3. 代理工作的隊列 - 代理的執行工作可以不再一個線程上

            [NSOperationQueue mainQueue] 代理在主線程上工作

            nil - 代理非同步工作

            [[NSOperationQueue alloc] init] - 代理在非同步工作

         

         注意:URLSession 本身的網路操作是非同步,無論指定什麼隊列,都是在非同步執行的

         - 在此指定的代理的工作隊列,表示發生網路事件後,希望在哪一個線程中工作!

         

         隊列的選擇依據與 NSURLConnection 非同步隊列選擇依據相同!

         -如果完成後需要做複雜(耗時)的處理,可以選擇非同步隊列

         -如果完成後直接更新UI,可以選擇主隊列

         

         強調:session本身工作的線程,與代理工作的線程是不一樣的

         */

        _session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:[NSOperationQueue mainQueue]];

URLSession sessionWithConfiguration:config delegate:self delegateQueue:[NSOperationQueue mainQueue]

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.