/** Send phone verification code*/-(void) startsenderyzmmessage{__blockintTimeout = -;//Countdown Timedispatch_queue_t queue = Dispatch_get_global_queue (Dispatch_queue_priority_default,0); dispatch_source_t _timer= Dispatch_source_create (Dispatch_source_type_timer,0,0, queue); Dispatch_source_set_timer (_timer,dispatch_walltime (NULL,0),1.0*nsec_per_sec,0);//executes per secondDispatch_source_set_event_handler (_timer, ^{ if(timeout<=0){//countdown end, closeDispatch_source_cancel (_timer); Dispatch_async (Dispatch_get_main_queue (),^{ //The countdown here is back to normal status. }); }Else{ //int minutes = TIMEOUT/60; intseconds = Timeout% -; NSString*strtime = [NSString stringWithFormat:@"%.2d", seconds]; if([Strtime isequaltostring:@"xx"]) {strtime=@" -"; } dispatch_async (Dispatch_get_main_queue (),^{ //countdown status Here, update countdown display }); Timeout--; } }); Dispatch_resume (_timer);}
ios-Send SMS Verification code Countdown