- 需求情景:每日签到弹框,三方登录绑手机提示,及其他身份信息每日提示一次等。
+ (BOOL)ApartOneDayMore {
//相隔至少一天
NSDate *lastDate = [[NSUserDefaults standardUserDefaults] objectForKey:@"signInEveryDayLastDate"];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"dd"];
NSString *lastDayStr = [formatter stringFromDate:lastDate];
NSString *nowDayStr = [formatter stringFromDate:[NSDate date]];
//一天有24*24*60秒,大于秒数就是隔天,小于时判断day数,不同也是隔天.返回true
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"signInEveryDayLastDate"]) {
if (([NSDate date].timeIntervalSince1970-lastDate.timeIntervalSince1970)>24*24*60) {
[[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:@"signInEveryDayLastDate"];
return true;
}
else if(nowDayStr.intValue!=lastDayStr.intValue) {
[[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:@"signInEveryDayLastDate"];
return true;
}
return false;
}
//否则,不存在这个字段,说明新装的,返回true
[[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:@"signInEveryDayLastDate"];
return true;
}