美文网首页
ios一天显示一次广告或弹窗

ios一天显示一次广告或弹窗

作者: 冰点雨 | 来源:发表于2020-05-30 15:12 被阅读0次

    废话不说,直接上代码

    //一天之内只能批量邀请一次
        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:@"网络错误,请稍后再试"];
        }];
    

    相关文章

      网友评论

          本文标题:ios一天显示一次广告或弹窗

          本文链接:https://www.haomeiwen.com/subject/rlthzhtx.html