iOS-判断今天第一次打开应用

2017-06-12  本文已影响0人  谁在呼叫贱队


判断今天登陆

+(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]));

}

上一篇 下一篇

猜你喜欢

热点阅读