How IOS starts and stops Runloop

Source: Internet
Author: User

#import "ViewController.h"

@interface Viewcontroller () <NSURLConnectionDataDelegate>

@property (nonatomic, assign) Cfrunloopref runloop;//keep the same thread C language

@end

@implementation Viewcontroller

-(void) Viewdidload {

[Super Viewdidload];

Dispatch_async (dispatch_get_global_queue (0, 0), ^{

Nsurlconnection *conn = [nsurlconnection connectionwithrequest:[nsurlrequest requestwithurl:@ ""] delegate:self];

Decide which queue the agent executes on

[Conn Setdelegatequeue:[[nsoperationqueue alloc] init]];

//Put on sub-thread, the loop of the child thread is not open by default, the listener returns the data event without sink time

So to manually start a child thread

[[Nsrunloop Currentrunloop] run];

Self.runloop = Cfrunloopgetcurrent ();

Cfrunlooprun (); Start

});

}

#pragma mark-<nsurlconnectiondatadelegate>

-(void) connection: (Nsurlconnection *) connection didreceiveresponse: (Nsurlresponse *) response{

}

-(void) connection: (Nsurlconnection *) connection didreceivedata: (NSData *) data{

}

-(void) connectiondidfinishloading: (nsurlconnection *) connection{

Close Runloop

Cfrunloopstop (Self.runloop); //Turn off maintain consistency

}

@end

How IOS starts and stops Runloop

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.