Skip to content

AlfredZY/AZTime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

全局倒计时管理 + 计算本地时间与服务器时间差

  • 直接复制AZTime文件夹到项目或者使用cocoapods pod 'AZTime', '~> 0.1.0'

  • AZTime主要提供了一个用于防止本地时间与服务器时间有偏差以及用户手动修改系统时间导致倒计时不准确的解决方案。

  • 使用起来分两步:

  1. 设置自动更新的URL
// 自动更新服务器时间偏移量
// 一般在AppDelegate里设置一次就可以了
[[AZCountdownManager sharedInstance] autoUpdateServerOffsetWithVerifyUrl:@"https://www.baidu.com"];
  1. 在需要使用倒计时的地方使用AZCountdownManager里合适的方法就行了

    例如一个有着倒计时功能列表里的一个cell,我们可以这样使用:

#import "TimerCell.h"

- (void)setModel:(TimeModel *)model {
    _model = model;
    __weak typeof(self) weakSelf = self;
    [[AZCountdownManager sharedInstance] addCountdownWithView:self // 该定时的生命跟随self(TimerCell)的生命周期
                                                 deadlineDate:model.date
                                                     interval:0.3
                                                     autoStop:YES
                                         leftTimeChangedBlock:^(NSTimeInterval leftTime, UIView *view, NSString *key) {
            __strong typeof(self) strongSelf = weakSelf;
            // update timer UI                   
    }];
}

About

全局倒计时管理 + 计算本地时间与服务器时间差

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors