限制一分钟内的弹窗次数方法

最近开发中需要对一个页面的弹窗限制只能一分钟内最多三次
为了适应要求,现记录如下

/*! 声明定义*/
@property (nonatomic , strong) NSDate * firstDate;
/*! 方法实现*/
- (BOOL)canShowToast{
    NSDate *d=[NSDate date];
    NSTimeInterval late=[d timeIntervalSince1970];
    if (!_firstDate) {
        _firstDate = d;
        return YES;
    }else{
        NSTimeInterval now=[_firstDate timeIntervalSince1970];
        NSTimeInterval cha=late-now;
        if (cha>20) {
            _firstDate = d;
            return YES;
        }
    }
    return NO;
}

猜你喜欢

转载自www.cnblogs.com/lovemargin/p/12375189.html