#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