//Background execution:Dispatch_async (Dispatch_get_global_queue (0,0), ^{ //something});//main thread Execution:Dispatch_async (Dispatch_get_main_queue (), ^{ //something});//Disposable Execution:Staticdispatch_once_t oncetoken;dispatch_once (&oncetoken, ^{ //code to be executed once});//delay of 2 seconds execution:DoubleDelayinseconds =2.0;d ispatch_time_t poptime= Dispatch_time (Dispatch_time_now, Delayinseconds *nsec_per_sec);d ispatch_after (Poptime, Dispatch_get_main_queue (),^(void){ //Code to is executed on the main queue after delay});
// Custom Queuedispatch_queue_t urls_queue = dispatch_queue_create ("myqueue" ^{ // your code});d ispatch_release (urls_queue);
//background 2 threads are executed in parallel, and then after 2 threads are finished, the results of the execution are summarizeddispatch_group_t Group =dispatch_group_create ();d ispatch_group_async (Group, Dispatch_get_global_queue (0,0), ^{ //thread one in parallel execution});d Ispatch_group_async (Group, Dispatch_get_global_queue (0,0), ^{ //threads executed in parallel two});d ispatch_group_notify (Group, Dispatch_get_global_queue (0,0), ^{ //Summary Results});
//keep apps up to 10 minutes long in the background//AppDelegate.h File@property (Assign, nonatomic) Uibackgroundtaskidentifier backgroundupdatetask;//appdelegate.m File- (void) Applicationdidenterbackground: (UIApplication *) application{[self beingbackgroundupdatetask]; //Add the code that you need to run long[self endbackgroundupdatetask];}- (void) beingbackgroundupdatetask{Self.backgroundupdatetask= [[UIApplication sharedapplication] beginbackgroundtaskwithexpirationhandler:^{[Self endbackgroundupdatetask]; }];}- (void) endbackgroundupdatetask{[[UIApplication sharedapplication] endBackgroundTask:self.backgroundUpdateTask]; Self.backgroundupdatetask=Uibackgroundtaskinvalid;}
IOS GCD Learning Notes