需求:
产品
代码实现:
在首页.m中
//一天之内只能批量邀请一次 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); [LiBao_Request libaoWithsuccess:^(LiBao_Result *result) { if (result.code.intValue==10000) { if ([ageDateString isEqualToString:nowDateString]) { NSLog(@"一天就显示一次"); }else{ self.imgurl=result.data.show_img; self.coupon_id=result.data.coupon_id; //创建视图 [self creatLiBao]; NSDate *nowDate = [NSDate date]; NSUserDefaults *dataUser = [NSUserDefaults standardUserDefaults]; [dataUser setObject:nowDate forKey:@"nowDate"]; [dataUser synchronize]; } }else{ //请求没有数据 NSLog(@"没有数据"); } } failure:^(NSError *error) { NSLog(@"请求失败"); }];