首页 > 其他分享 >Apple开发_判断相隔一天

Apple开发_判断相隔一天

时间:2022-11-09 11:45:08浏览次数:44  
标签:判断 Apple standardUserDefaults signInEveryDayLastDate date NSDate NSUserDefaults 

  • 需求情景:每日签到弹框,三方登录绑手机提示,及其他身份信息每日提示一次等。
+ (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;
}

标签:判断,Apple,standardUserDefaults,signInEveryDayLastDate,date,NSDate,NSUserDefaults,
From: https://www.cnblogs.com/CH520/p/9588888.html

相关文章