IOS Verification Code countdown (implemented by GCD) and ios Verification Code countdown to gcd
+ (Void) verificationCode :( void (^) () blockYes blockNo :( void (^) (id time) blockNo {_ block int timeout = 60; // countdown time dispatch_queue_t queue = minute (hour, 0); dispatch_source_t _ timer = dispatch_source_create (hour, 0, 0, queue); minute (_ timer, dispatch_walltime (NULL, 0), 1.0 * NSEC_PER_SEC, 0); // execute dispatch_source_set_event_handler (_ timer, ^ {if (timeout <= 0) {// The countdown ends, disable dispatch_source_cancel (_ timer); dispatch_async (dispatch_get_main_queue (), ^ {// set blockYes ();}) according to your needs ();});} else {// int minutes = timeout/60; int seconds = timeout % 60; NSString * strTime = [NSString stringWithFormat: @ "%. 2d ", seconds]; dispatch_async (dispatch_get_main_queue (), ^ {// set the NSLog (@" ____ % @ ", strTime) according to your needs ); blockNo (strTime) ;}); timeout -- ;}}); dispatch_resume (_ timer );}