hanfengs
4/3/2019 - 9:36 AM

每天一次的操作,比如签到;提醒升级弹框等等

每天一次的操作,比如签到;提醒升级弹框等等


NSDate *nowDate = [NSDate date];
NSUserDefaults *dataUser = [NSUserDefaults standardUserDefaults];
[dataUser setObject:nowDate forKey:@"nowDate"];
[dataUser synchronize];

NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
NSDate *now = [NSDate date];
NSDate *agoDate = [userDefault objectForKey:@"nowDate"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];

NSString *ageDateString = [dateFormatter stringFromDate:agoDate];
NSString *nowDateString = [dateFormatter stringFromDate:now];
if ( [ageDateString isEqualToString:nowDateString]) {
  NSLog(@"已经完成过每日一次的操作");
}else{
  NSLog(@"开始每日一次的操作");
}