废话不说,直接上代码
//一天之内只能批量邀请一次
NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
// NSLog(@"之前时间:%@", [userDefault objectForKey:@"nowDate"]);//之前存储的时间
// NSLog(@"现在时间%@",[NSDate date]);//现在的时间
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];
// NSLog(@"日期比较:之前:%@ 现在:%@",ageDateString,nowDateString);
[[BaseHttpRequest sharedInstance] getWithUrl:url_ad parameters:dic success:^(NSDictionary *responseDict, NSInteger code, NSString *message) {
if (code == 1) {
if ([ageDateString isEqualToString:nowDateString]) {
NSLog(@"一天就显示一次");
}else{
//创建视图
[self creatLiBao];
NSDate *nowDate = [NSDate date];
NSUserDefaults *dataUser = [NSUserDefaults standardUserDefaults];
[dataUser setObject:nowDate forKey:@"nowDate"];
[dataUser synchronize];
}
}else{
[SVProgressHUD showMessage:message];
}
} failur:^(NSError *error) {
[SVProgressHUD showErrorWithMessage:@"网络错误,请稍后再试"];
}];
网友评论