After the app enters the backstage, realizes the SMS verification code time uninterrupted countdown
//get time when the app enters the background of the phone and the front of the phone- (void) Applicationdidenterbackground: (UIApplication *) Application {nsdate* dat = [nsdate datewithtimeintervalsincenow:0]; Nstimeinterval a=[dat timeIntervalSince1970] * +; NSString*timestring = [NSString stringWithFormat:@"%.0f", a]; Nsdictionary*dic = @{@" Time": TimeString}; [[Nsnotificationcenter Defaultcenter]postnotificationname:@"background" Object: nil userinfo:dic];}- (void) Applicationwillenterforeground: (UIApplication *) Application {nsdate* dat = [nsdate datewithtimeintervalsincenow:0]; Nstimeinterval a=[dat timeIntervalSince1970] * +; NSString*timestring = [NSString stringWithFormat:@"%.0f", a]; Nsdictionary*dic = @{@" Time": TimeString}; [[Nsnotificationcenter Defaultcenter]postnotificationname:@"foreground" Object: nil userinfo:dic];}
//Login Interface Implementation notification Call@property (nonatomic) Nsinteger Secondcountdown; @property (nonatomic) Nsinteger integer1; @property (nonatomic) Nsinteger Integer2;-(void) Viewwillappear: (BOOL) animated{[[Nsnotificationcenter defaultcenter] addobserver:self selector: @selector ( Appgoforeground:) Name:@"foreground" Object: nil]; [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (appgobackground:) Name:@"background" Object: nil]; Self.navigationController.navigationBarHidden=YES;}- (void) Appgobackground: (Nsnotification *) notification{_integer1= [notification.userinfo[@" Time"] IntegerValue]; }- (void) Appgoforeground: (Nsnotification *) notification{Nsinteger integer= [notification.userinfo[@" Time"] IntegerValue]; _integer2= (integer-_integer1)/ +; _secondcountdown= _secondcountdown-_integer2; }
Mobile SMS Verification Code TIME Countdown