判断今天登陆
+(BOOL)isOpenToDayTag:(NSString *)tag{
tag =[NSString stringWithFormat:@"%@ToDay",tag];
BOOL bol =[self isSameOpenToday:[NSDate date]Tag:tag];
if(!bol){
[[NSUserDefaults standardUserDefaults]setObject:[NSDate new]forKey:tag];
}
return bol;
}
+(BOOL)isSameOpenToday:(NSDate *)anotherDate Tag:(NSString *)tag{
NSCalendar *calendar =[NSCalendar currentCalendar];
NSDate *oldDate =[[NSUserDefaults standardUserDefaults]objectForKey:tag];
NSDateComponents *components1 =[calendar components:(NSCalendarUnitYear
| NSCalendarUnitMonth
| NSCalendarUnitDay)
fromDate:oldDate];
NSDateComponents *components2 =[calendar components:(NSCalendarUnitYear
| NSCalendarUnitMonth
| NSCalendarUnitDay)
fromDate:anotherDate];
return([components1 year]==[components2 year]
&&[components1 month]==[components2 month]
&&[components1 day]==[components2 day]);
}
判断七天内登陆
+(BOOL)isOpenToWeekTag:(NSString *)tag{
tag =[NSString stringWithFormat:@"%@ToWeek",tag];
BOOL bol =[self isSameOpenToweek:[NSDate date]Tag:tag];
if(!bol){
[[NSUserDefaults standardUserDefaults]setObject:[NSDate new]forKey:tag];
}
return bol;
}
+(BOOL)isSameOpenToweek:(NSDate *)anotherDate Tag:(NSString *)tag{
NSCalendar *calendar =[NSCalendar currentCalendar];
NSDate *oldDate =[[NSUserDefaults standardUserDefaults]objectForKey:tag];
if(!oldDate){
return YES;
}
NSDateComponents *components1 =[calendar components:(NSCalendarUnitYear
| NSCalendarUnitMonth
| NSCalendarUnitDay)
fromDate:oldDate];
NSDateComponents *components2 =[calendar components:(NSCalendarUnitYear
| NSCalendarUnitMonth
| NSCalendarUnitDay)
fromDate:anotherDate];
return([components1 year]==[components2 year]
&&[components1 month]==[components2 month]
&&([components1 day]+ 6)>([components2 day]));
}