zoukankan      html  css  js  c++  java
  • 手机短信验证码时间倒计时

    app 进入后台后,实现手机短信验证码时间不间断倒计时

    //当app进入手机后台和手机前台时获取时间
    - (void)applicationDidEnterBackground:(UIApplication *)application {
        NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
        NSTimeInterval a=[dat timeIntervalSince1970] * 1000;
        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] * 1000;
        NSString *timeString = [NSString stringWithFormat:@"%.0f", a];
        NSDictionary *dic = @{@"time":timeString};
        
        [[NSNotificationCenter defaultCenter]postNotificationName:@"foreground" object:nil userInfo:dic];
    
    }
    //登录界面实现通知调用
    
    
    @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)/1000;
        
        _secondCountDown = _secondCountDown - _integer2;
        
    }
  • 相关阅读:
    JS获取今天的日期
    领域模型vs数据模型,应该怎么用?
    如何让技术想法更容易被理解?
    如何做好技术 Team Leader
    回归分析中常见的“门槛模型”!
    有了数据湖,距离数据仓库消失还有几年?
    数据治理 VS 公司治理、IT治理、数仓治理
    Sentence-seven basic patterns 英语句子结构
    VM的Linux CentOS系统的VMTools的手动安装
    linux下IPTABLES配置详解
  • 原文地址:https://www.cnblogs.com/sayimba/p/5725656.html
Copyright © 2011-2022 走看看