Mobile SMS Verification Code TIME Countdown

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.