// // YOUPAILZHomeVC.m // MSYOUPAI // // Created by CY on 2022/2/28. // Copyright © 2022 MS. All rights reserved. // #import "YOUPAILZHomeVC.h" // controller #import "YOUPAILCUpdateVersionVC.h" #import "YOUPAILPYoungPwdVC.h" #import "YOUPAILPYoungForgetPWD.h" #import "YOUPAILZLiveAudienceVC.h" #import "YOUPAILZVipVC.h" #import "YOUPAIZYSearchVC.h" #import "YOUPAILZHomeActiveVC.h" #import "MSYMineinfoEditVC.h" //window #import "YOUPAILPYoungCloseWindow.h" #import "YOUPAILPYoungOpenWindow.h" #import "YOUPAILZSignWindow.h" #import "YOUPAIHRWebWindow.h" #import "YOUPAIZYAdvertWindow.h" #import "YOUPAIZYFirstRechargeWindow.h" #import "YOUPAILZExposureWindow.h" // category #import "UIViewController+TFPresent.h" // model #import "YOUPAILCFirstRechargeModel.h" #import "YOUPAILZHomeTVModel.h" // view #import "JXCategoryView.h" #import "SDCycleScrollView.h" #import "YOUPAILZGiftNoticeCell.h" #import "YOUPAILZInfoImperfectView.h" #import "YOUPAIFinishMsgWindow.h" #import "YOUPAILCWriteMesVC.h" @interface YOUPAILZHomeVC (){ dispatch_source_t _timer; } @property (nonatomic, weak) SDCycleScrollView *youpaipbannerView; @property (nonatomic, weak) UIView *youpaiptvBgV; @property (nonatomic, weak) UIButton *youpaipnoticeDescBtn; // 如何上电视按钮 @property (nonatomic, strong) NSMutableArray *youpaipTVDataSource; // 电视数据 @property (nonatomic, weak) YOUPAILZInfoImperfectView *infoImperfectView; @property (nonatomic,strong)NSTimer *youpaipTVTimer; @property (nonatomic, assign)NSInteger currentTVLockTimer; @property (nonatomic, strong) NSString *youpaipTVUrl; @property(nonatomic,strong)SDCycleScrollView* youpaipSDCscrollView; @property (strong, nonatomic) YOUPAILCFirstRechargeModel *youpaipfirstRechargeModel; @end @implementation YOUPAILZHomeVC - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:YES animated:animated]; [self youpaifDetectVersionUpdates]; [self youpaifDetectYoungMode]; [self youpaifloadFinishMsgStatus]; } - (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; [self.navigationController setNavigationBarHidden:NO animated:animated]; } - (void)viewDidLoad { [super viewDidLoad]; self.youpaipTVDataSource = [NSMutableArray array]; [self youpaifinitConfig]; [self youpaifloadLevelInfo]; // [self youpaifrequestSignData]; [self youpaifloadAdvert]; [self youpaifrequestTVData]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifuserOnlineUpdate) name:@"youpaifuserOnlineUpdate" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifTVDataUpdate:) name:@"VQUHomeTVDataNotification" object:nil]; } //appid登录完善资料 -(void)youpaifloadFinishMsgStatus{ YOUPAILCUserModel *userModel = [LCSaveModel getUserModel]; if (userModel.youpaipuserinfo.youpaipfinish_status == 0) { YOUPAIFinishMsgWindow *VC= [[YOUPAIFinishMsgWindow alloc]init]; VC.vWidth = KScreenWidth - (47.5*2); VC.vHeight = 330; VC.youpaipfinishMsgdelegate = self; VC.isTouchDismiss = NO; [self TFPresentVC:VC completion:^{ }]; } } -(void)youpaifjumFinishMsgClick{ YOUPAILCWriteMesVC *msg = [[YOUPAILCWriteMesVC alloc]init]; msg.youpaipinviteCodeStr = [LCTools getPasteString]; msg.isFinishMsg = YES; [self.navigationController pushViewController:msg animated:YES]; } - (void)youpaifinitUI{ UIView *youpaipnavV = [[UIView alloc] init]; youpaipnavV.backgroundColor = [UIColor whiteColor]; [self.view addSubview:youpaipnavV]; [youpaipnavV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.right.offset(0.0f); make.height.offset(StatusBarHeight + 54.0f); }]; // UIButton *youpaipsearchBtn = [UIButton buttonWithType:UIButtonTypeCustom]; // [youpaipsearchBtn setImage:[UIImage imageNamed:@"vqu_images_home_search"] forState:UIControlStateNormal]; // [youpaipsearchBtn addTarget:self action:@selector(youpaifsearchClick) forControlEvents:UIControlEventTouchUpInside]; // [youpaipnavV addSubview:youpaipsearchBtn]; // [youpaipsearchBtn mas_makeConstraints:^(MASConstraintMaker *make) { // make.right.offset(-11.0f); // make.bottom.offset(-13.5f); // make.size.mas_offset(CGSizeMake(25.0f, 25.0f)); // }]; UIButton *youpaipSuperExposureBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [youpaipSuperExposureBtn setImage:[UIImage imageNamed:@"vqu_images_home_super_exposure"] forState:UIControlStateNormal]; [youpaipSuperExposureBtn addTarget:self action:@selector(youpaifSuperExposureClick) forControlEvents:UIControlEventTouchUpInside]; [youpaipnavV addSubview:youpaipSuperExposureBtn]; [youpaipSuperExposureBtn mas_makeConstraints:^(MASConstraintMaker *make) { // make.right.equalTo(youpaipsearchBtn.mas_left).offset(-8.5f); make.right.offset(-11.0f); make.bottom.offset(-16.0f); make.size.mas_offset(CGSizeMake(72.0f, 22.0f)); }]; JXCategoryTitleView *youpaipcategoryView = [[JXCategoryTitleView alloc] init]; youpaipcategoryView.backgroundColor = [UIColor whiteColor]; youpaipcategoryView.titles = self.titles; youpaipcategoryView.delegate = self; youpaipcategoryView.titleSelectedColor = LZ273145Color; youpaipcategoryView.titleColor = LZ475A7DColor; youpaipcategoryView.titleColorGradientEnabled = YES; youpaipcategoryView.titleFont = LCFont(18.0f); youpaipcategoryView.titleSelectedFont = LCBoldFont(18.0f); youpaipcategoryView.cellWidth = JXCategoryViewAutomaticDimension; youpaipcategoryView.cellSpacing = 20.0f; youpaipcategoryView.averageCellSpacingEnabled = NO; [youpaipnavV addSubview:youpaipcategoryView]; JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init]; lineView.verticalMargin = 10.0f; lineView.indicatorHeight = 3.0f; lineView.indicatorWidth = 10.0f; lineView.indicatorColor = LZ7C69FEColor; youpaipcategoryView.indicators = @[lineView]; JXCategoryListContainerView *pagerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_CollectionView delegate:self]; pagerView.listCellBackgroundColor = LZFAFAFCColor; [self.view addSubview:pagerView]; youpaipcategoryView.listContainer = pagerView; [youpaipcategoryView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.bottom.offset(0.0f); make.right.equalTo(youpaipSuperExposureBtn.mas_left).offset(-8.5f); make.height.offset(54.0f); }]; UIView *youpaiptvBgV = [[UIView alloc] init]; youpaiptvBgV.layer.cornerRadius = ScaleSize(10.0f); youpaiptvBgV.clipsToBounds = YES; youpaiptvBgV.backgroundColor = [HexColorFromRGB(0xB2BAF9) colorWithAlphaComponent:0.31f]; [self.view addSubview:youpaiptvBgV]; self.youpaiptvBgV = youpaiptvBgV; [youpaiptvBgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(ScaleSize(12.0f)); make.right.offset(ScaleSize(-12.0f)); make.top.offset(StatusBarHeight + 54.0f); make.height.offset(ScaleSize(0.0f)); }]; UIImageView *tvImgV = [[UIImageView alloc] init]; tvImgV.image = [UIImage imageNamed:@"vqu_images_home_tv"]; [youpaiptvBgV addSubview:tvImgV]; [tvImgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.bottom.offset(0.0f); make.width.offset(ScaleSize(72.0f)); }]; UIButton *youpaipnoticeDescBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [youpaipnoticeDescBtn setImage:[UIImage imageNamed:@"vqu_images_home_tv_desc_h"] forState:UIControlStateNormal]; [youpaipnoticeDescBtn setTitle:@"如何上电视" forState:UIControlStateNormal]; [youpaipnoticeDescBtn setTitleColor:LZ7C69FEColor forState:UIControlStateNormal]; youpaipnoticeDescBtn.titleLabel.font = LCFont(10.0f); youpaipnoticeDescBtn.layer.cornerRadius = 9.0f; youpaipnoticeDescBtn.clipsToBounds = YES; youpaipnoticeDescBtn.layer.borderColor = LZ7C69FEColor.CGColor; youpaipnoticeDescBtn.layer.borderWidth = 0.5f; [youpaipnoticeDescBtn addTarget:self action:@selector(youpaipnoticeDescBtnClick) forControlEvents:UIControlEventTouchUpInside]; [youpaipnoticeDescBtn setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft]; [youpaiptvBgV addSubview:youpaipnoticeDescBtn]; self.youpaipnoticeDescBtn = youpaipnoticeDescBtn; [youpaipnoticeDescBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(youpaiptvBgV); make.right.offset(-10.0f); make.size.mas_offset(CGSizeMake(70.0f, 18.0f)); }]; [pagerView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.offset(0.0f); make.bottom.offset(-TabbarHeight); make.top.equalTo(youpaiptvBgV.mas_bottom).offset(9.0f); }]; SDCycleScrollView *youpaipbannerView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:nil]; youpaipbannerView.autoScrollTimeInterval = 3.0;//2s轮播 // youpaipbannerView.imageURLStringsGroup = @[@"",@""]; youpaipbannerView.pageControlStyle = SDCycleScrollViewPageContolStyleNone; youpaipbannerView.backgroundColor = [UIColor clearColor]; youpaipbannerView.scrollDirection = UICollectionViewScrollDirectionVertical; youpaipbannerView.pageControlStyle = SDCycleScrollViewPageContolStyleNone; youpaipbannerView.mainView.userInteractionEnabled = NO; [youpaiptvBgV addSubview:youpaipbannerView]; self.youpaipbannerView = youpaipbannerView; [youpaipbannerView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.bottom.offset(0.0f); make.left.equalTo(tvImgV.mas_right).offset(0.0f); make.right.equalTo(youpaipnoticeDescBtn.mas_left).offset(0.0f); }]; @weakify(self); [youpaipbannerView setItemDidScrollOperationBlock:^(NSInteger currentIndex) { @strongify(self); NSInteger lock_time = [self.youpaipTVDataSource[currentIndex].youpaiplock_time integerValue]; if (lock_time != 0) { self.currentTVLockTimer = lock_time; self.youpaipTVDataSource[currentIndex].youpaiplock_time = @"0"; [self youpaifstartTimer]; }else{ [self youpaifstopTimer]; } if (lock_time == 0) { lock_time = 3; } self.youpaipbannerView.autoScrollTimeInterval = lock_time; }]; [self loadRightSDCView]; [self youpaifinitInfoImperfectView]; } - (void)youpaipnoticeDescBtnClick{ ZCBaseWebVC * vc = [[ZCBaseWebVC alloc]init]; vc.contentUrl = self.youpaipTVUrl; [self.navigationController pushViewController:vc animated:YES]; } -(void)loadRightSDCView{ SDCycleScrollView *rightBannerView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(KScreenWidth - 12.0f - 49.0f, KScreenHeight - TabbarHeight - 12.0f-39-19-50, 50, 50.0f) delegate:self placeholderImage:[UIImage imageNamed:@""]]; self.youpaipSDCscrollView = rightBannerView; rightBannerView.bannerImageViewContentMode = UIViewContentModeScaleAspectFit; rightBannerView.autoScrollTimeInterval = 3.0;//2s轮播 rightBannerView.pageControlStyle = SDCycleScrollViewPageContolStyleNone; rightBannerView.backgroundColor = [UIColor clearColor]; [self.view addSubview:rightBannerView]; [self youpaifloadFirstRecharge]; } -(void)youpaifloadFirstRecharge{ [LCHttpHelper requestWithURLString:GetAdvert parameters:@{@"position":@"2"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 self.youpaipfirstRechargeModel = [YOUPAILCFirstRechargeModel mj_objectWithKeyValues:dict[@"data"]]; NSMutableArray *imgUrlArray = [NSMutableArray new]; for (YOUPAILCBannerModel* model in self.youpaipfirstRechargeModel.youpaiplist) { [imgUrlArray addObject:[LCTools getImageUrlWithAddress:model.youpaipimage]]; } self.youpaipSDCscrollView.imageURLStringsGroup = imgUrlArray; if (self.youpaipfirstRechargeModel.youpaipis_open == 1) { self.youpaipSDCscrollView.hidden = NO; }else{ self.youpaipSDCscrollView.hidden = YES; } } } failure:^(NSError *error) {}]; } #pragma mark - SDCycleScrollViewDelegate - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index { YOUPAILCBannerModel* model = self.youpaipfirstRechargeModel.youpaiplist[index]; if (model.youpaiplink_type==1) { ZCBaseWebVC* baseWeb = [[ZCBaseWebVC alloc]init]; baseWeb.contentUrl = model.youpaiplink_url; [self.navigationController pushViewController:baseWeb animated:YES]; }else if (model.youpaiplink_type==2||model.youpaiplink_type==3){ [self youpaifpageToStr:model.youpaiplink_url]; } } // 开始计时 - (void)youpaifstartTimer{ if (self.youpaipTVTimer == nil) { self.youpaipTVTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(youpaiftimerAction) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop] addTimer:self.youpaipTVTimer forMode:NSRunLoopCommonModes]; } [self.youpaipnoticeDescBtn setImage:[UIImage imageNamed:@"vqu_images_home_tv_desc_n"] forState:UIControlStateNormal]; [self.youpaipnoticeDescBtn setTitle:[NSString stringWithFormat:@"锁屏中%@s",@(self.currentTVLockTimer)] forState:UIControlStateNormal]; [self.youpaipnoticeDescBtn setTitleColor:LZA3AABEColor forState:UIControlStateNormal]; self.youpaipnoticeDescBtn.layer.borderColor = LZA3AABEColor.CGColor; } // 结束计时 - (void)youpaifstopTimer{ [self.youpaipTVTimer invalidate]; self.youpaipTVTimer = nil; [self.youpaipnoticeDescBtn setImage:[UIImage imageNamed:@"vqu_images_home_tv_desc_h"] forState:UIControlStateNormal]; [self.youpaipnoticeDescBtn setTitle:@"如何上电视" forState:UIControlStateNormal]; self.youpaipnoticeDescBtn.layer.borderColor = LZ7C69FEColor.CGColor; [self.youpaipnoticeDescBtn setTitleColor:LZ7C69FEColor forState:UIControlStateNormal]; } - (void)youpaiftimerAction{ self.currentTVLockTimer --; [self.youpaipnoticeDescBtn setImage:[UIImage imageNamed:@"vqu_images_home_tv_desc_n"] forState:UIControlStateNormal]; [self.youpaipnoticeDescBtn setTitle:[NSString stringWithFormat:@"锁屏中%@s",@(self.currentTVLockTimer)] forState:UIControlStateNormal]; [self.youpaipnoticeDescBtn setTitleColor:LZA3AABEColor forState:UIControlStateNormal]; if (self.currentTVLockTimer < 0) { [self youpaifstopTimer]; } } - (void)youpaifinitInfoImperfectView{ if ([LCSaveData getWhiteVersion]) { return; } YOUPAILZInfoImperfectView *infoImperfectView = [[YOUPAILZInfoImperfectView alloc] initWithFrame:CGRectMake(12, KScreenHeight, KScreenWidth - 24.0f, 39.0f)]; @weakify(self); [infoImperfectView setGoEditUserInfoPageBlock:^{ @strongify(self); MSYMineinfoEditVC * editvc = [MSYMineinfoEditVC new]; [self.navigationController pushViewController:editvc animated:true]; }]; [self.view addSubview:infoImperfectView]; self.infoImperfectView = infoImperfectView; } /** 如果你需要自定义cell样式,请在实现此代理方法返回你的自定义cell的class。 */ - (Class)customCollectionViewCellClassForCycleScrollView:(SDCycleScrollView *)view{ if (view == self.youpaipbannerView) { return YOUPAILZGiftNoticeCell.class; } return nil; } /** 如果你自定义了cell样式,请在实现此代理方法为你的cell填充数据以及其它一系列设置 */ - (void)setupCustomCell:(UICollectionViewCell *)cell forIndex:(NSInteger)index cycleScrollView:(SDCycleScrollView *)view{ YOUPAILZGiftNoticeCell *itemCell = (YOUPAILZGiftNoticeCell *)cell; [itemCell youpaifreloadWithModel:self.youpaipTVDataSource[index]]; } - (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView{ return self.titles.count; } - (id)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index{ YOUPAILZHomeActiveVC *vc = [[YOUPAILZHomeActiveVC alloc] init]; vc.youpaiprequestUrl = self.urls[index]; @weakify(self); [vc setShowUserInfoImperfectBlock:^(BOOL isShow) { @strongify(self); if (isShow) { [UIView animateWithDuration:0.25f animations:^{ self.infoImperfectView.mj_y = KScreenHeight - TabbarHeight - 12.0f - self.infoImperfectView.mj_h; }]; } }]; return vc; } - (NSArray *)titles{ return @[@"推荐",@"在线"]; } - (NSArray *)urls{ return @[HomeRecommend,HomeOnlineList]; } /// 搜索 - (void)youpaifsearchClick{ YOUPAIZYSearchVC* seach = [[YOUPAIZYSearchVC alloc]init]; [self pushEffectPresentToVC:seach]; } /// 超级曝光 - (void)youpaifSuperExposureClick{ YOUPAILZExposureWindow *window = [[YOUPAILZExposureWindow alloc] init]; @weakify(self); [window setGoVipPageBlock:^{ @strongify(self); YOUPAILZVipVC* vc = [[YOUPAILZVipVC alloc]init]; [self.navigationController pushViewController:vc animated:YES]; }]; [self TFPresentVC:window completion:nil]; } /// 获取上电视数据 - (void)youpaifrequestTVData{ @weakify(self); [LCHttpHelper requestWithURLString:GetOntvList parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 self.youpaipTVDataSource = [YOUPAILZHomeTVModel mj_objectArrayWithKeyValuesArray:[dict objectForKey:@"data"]]; NSMutableArray *arr = [NSMutableArray array]; for (YOUPAILZHomeTVModel *model in self.youpaipTVDataSource) { [arr addObject:@""]; } if (arr.count != 0) { self.youpaiptvBgV.hidden = NO; [self.youpaiptvBgV mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.offset(ScaleSize(12.0f)); make.right.offset(ScaleSize(-12.0f)); make.top.offset(StatusBarHeight + 54.0f + ScaleSize(9.0f)); make.height.offset(ScaleSize(60.0f)); }]; } self.youpaipbannerView.imageURLStringsGroup = arr; } } failure:^(NSError *error) { }]; } - (void)youpaifTVDataUpdate:(NSNotification *)notify{ NSDictionary *dataDic = notify.userInfo; YOUPAILZHomeTVModel *notifyModel = dataDic[@"model"]; if (self.youpaipbannerView.currentIndex + 1 >= self.youpaipTVDataSource.count - 1) { [self.youpaipTVDataSource addObject:notifyModel]; }else{ [self.youpaipTVDataSource insertObject:notifyModel atIndex:self.youpaipbannerView.currentIndex + 1]; } NSMutableArray *arr = [NSMutableArray array]; for (YOUPAILZHomeTVModel *model in self.youpaipTVDataSource) { [arr addObject:@""]; } self.youpaipbannerView.imageURLStringsGroup = arr; [self.youpaipbannerView makeScrollViewScrollToIndex:self.youpaipbannerView.currentIndex]; } #pragma mark-广告弹框 -(void)youpaifloadAdvert{ @weakify(self); [LCHttpHelper requestWithURLString:GetAdvert parameters:@{@"source_id":@"2"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 NSInteger status = [dict[@"data"][@"advert"][@"status"] integerValue]; NSString *image = dict[@"data"][@"advert"][@"image"]; NSInteger link_type = [dict[@"data"][@"advert"][@"link_type"] integerValue]; NSString *link_url = dict[@"data"][@"advert"][@"link_url"]; NSInteger window_type = [dict[@"data"][@"advert"][@"window_type"] integerValue]; if (status == 1 && image.length>5) { if (window_type == 2) { YOUPAIHRWebWindow *window = [[YOUPAIHRWebWindow alloc] init]; window.isTouchDismiss = YES; window.youpaipurl = dict[@"data"][@"advert"][@"window_link"]; window.youpaipwidth = [dict[@"data"][@"advert"][@"width"] floatValue]; window.youpaipheight = [dict[@"data"][@"advert"][@"height"] floatValue]; window.youpaipgravity = dict[@"data"][@"advert"][@"gravity"]; [self TFPresentVC:window completion:^{}]; }else{ YOUPAIZYAdvertWindow *VC= [[YOUPAIZYAdvertWindow alloc]init]; VC.youpaipdelegate = self; VC.vWidth = KScreenWidth -30; VC.vHeight = KScreenWidth-30; VC.youpaipimageurl = image; VC.youpaiplink_type = link_type; VC.youpaiplink_url = link_url; VC.isTouchDismiss = YES; [self TFPresentVC:VC completion:^{}]; } } } } failure:^(NSError *error) {}]; } //获取首冲弹框数据 -(void)youpaifloadAdvert1{ if ([NSStringFromClass([LCTools getContainNavigationControllerCurrentVC].class) isEqual:@"YOUPAILZChatRoomVC"]) { return; } @weakify(self); [LCHttpHelper requestWithURLString:GetAdvert parameters:@{@"position":@"6"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 YOUPAILCFirstRechargeModel *firstRechargeModel1 = [YOUPAILCFirstRechargeModel mj_objectWithKeyValues:dict[@"data"]]; for (int i = 0; i60*60*24) { [self youpaifcheckAppUpdate:NO]; }else{ } } } /// 获取等级图标 - (void)youpaifloadLevelInfo{ [LCHttpHelper requestWithURLString:LevelInfo parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 NSDictionary* levelInfo = [dict objectForKey:@"data"]; [LCSaveData saveLevelInfo:levelInfo]; } } failure:^(NSError *error) { }]; [LCHttpHelper requestWithURLString:AllBadge parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 NSDictionary* data = [dict objectForKey:@"data"]; NSDictionary* badge = [data objectForKey:@"badge"]; NSDictionary* noble = [data objectForKey:@"noble"]; [LCSaveData saveBadgeInfo:badge]; [LCSaveData saveNobleInfo:noble]; } } failure:^(NSError *error) { }]; } /// 获取签到数据 - (void)youpaifrequestSignData{ @weakify(self); [LCHttpHelper requestWithURLString:UserSign parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 NSString *msg = [[dict objectForKey:@"data"] objectForKey:@"msg"]; NSString *beans = [[dict objectForKey:@"data"] objectForKey:@"beans"]; NSString *link = [[dict objectForKey:@"data"] objectForKey:@"link"]; YOUPAILZSignWindow *vc = [[YOUPAILZSignWindow alloc]init]; vc.youpaipmsg = msg; vc.youpaipbeans = beans; vc.youpaiplink = link; vc.isTouchDismiss = YES; [vc setGoSignBlock:^(NSString * _Nonnull signUrl) { @strongify(self); ZCBaseWebVC* vc = [[ZCBaseWebVC alloc]init]; vc.contentUrl = signUrl; [self.navigationController pushViewController:vc animated:YES]; }]; [self TFPresentVC:vc completion:^{ }]; } } failure:^(NSError *error) {}]; } /// 更新在线状态 -(void)youpaifuserOnlineUpdate{ NSLog(@"youpaifuserOnlineUpdate 更新在线状态"); if (self->_timer) { dispatch_source_cancel(self->_timer); } if ([LCSaveData getTokenString] == nil) { return; } [LCHttpHelper requestWithURLString:onlineUpdate parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 NSInteger user_online_open = [[[dict objectForKey:@"data"]objectForKey:@"user_online_open"] integerValue]; int user_online_time = [[[dict objectForKey:@"data"]objectForKey:@"user_online_time"] intValue]; if (user_online_open == 1) { __block int timeout= user_online_time; dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); self->_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue); dispatch_source_set_timer(self->_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行 dispatch_source_set_event_handler(self->_timer, ^{ if(timeout<=0){ dispatch_source_cancel(self->_timer); dispatch_async(dispatch_get_main_queue(), ^{ [self youpaifuserOnlineUpdate]; }); }else{ NSString *strTime = [NSString stringWithFormat:@"%.2dS",timeout]; dispatch_async(dispatch_get_main_queue(), ^{ //设置界面的按钮显示 根据自己需求设置 // NSLog(@"strTime strTime %@",strTime); // // NSLog(@"当前时间挫%lld",[[LCTools getCurrentTimestamp] longLongValue]); }); timeout--; }}); dispatch_resume(self->_timer); } } } failure:^(NSError *error) {}]; } //add bu leo checkVersion 检查版本更新 -(void)youpaifcheckAppUpdate:(BOOL)need { [LCHttpHelper requestWithURLString:CheckUpdateVersion parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary *dict = (NSDictionary *)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0){ NSString *newVersion = [[dict objectForKey:@"data"] objectForKey:@"newversion"]; // NSString *myVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]; NSString *app_build = [[UIApplication sharedApplication] appVersion]; if ([newVersion compare:app_build options:NSCaseInsensitiveSearch]>0) { YOUPAILCUpdateVersionVC *VC= [[YOUPAILCUpdateVersionVC alloc]init]; VC.youpaipenforce = [[[dict objectForKey:@"data"] objectForKey:@"enforce"]integerValue]; VC.youpaipdownLoadUrl = [[dict objectForKey:@"data"] objectForKey:@"downloadurl"]; VC.youpaipversionStr = [NSString stringWithFormat:@"版本号:%@",newVersion]; VC.youpaipupdateText = [[dict objectForKey:@"data"] objectForKey:@"upgradetext"]; VC.vWidth = KScreenWidth - 70; NSDictionary *attrs = @{NSFontAttributeName : [UIFont systemFontOfSize:14]}; CGSize maxSize= [VC.youpaipupdateText boundingRectWithSize:CGSizeMake(VC.vWidth-116,66) options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size; if(maxSize.height<28) { maxSize.height = 28; }else{ maxSize.height = maxSize.height+20; } VC.vHeight = VC.vWidth*203/305.0 +86 + maxSize.height + 120; VC.isTouchDismiss = YES; if(VC.youpaipenforce == NO) [self TFPresentVC:VC completion:^{ NSDate *newData = [NSDate date]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSString *dataString = [dateFormatter stringFromDate:newData]; [LCSaveData saveUpdateTime:dataString]; }]; else{ VC.isTouchDismiss = NO; [self TFPresentVC:VC completion:^{ }]; } }else{ NSLog(@"dict === %@,%d",dict,need); if (need) { [ZCHUDHelper showTitle:@"已经是最新版本"]; } } } NSLog(@"dict === %@,%d",dict,need); } failure:^(NSError *error) { }]; } #pragma mark 青少年模式 /// 检测青少年模式 - (void)youpaifDetectYoungMode{ //青少年模式 //先判断是否设置了青少年模式 kAppDelegate.kadolescentStatus = [LCSaveData getYoungMode]; if(kAppDelegate.kadolescentStatus == 1){ [self youpaifshowYoungCloseWindow]; }else{ //在判断是否提醒过 //检查更新 根据时间戳 设定12小时/一天之内调用一次 NSString* updateTime = [LCSaveData getYoungNoticeTime]; NSDate * newData = [NSDate date]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; if (!updateTime) { NSString* dataString = [dateFormatter stringFromDate:newData]; [LCSaveData saveYoungNoticeTime:dataString]; //弹出设置青少年模式弹窗 //要不要检查一下status 防止卸载后重装 @weakify(self); [self youpaifAdenscentStatus:^{ @strongify(self); [self youpaifshowYoungCloseWindow]; } closed:^{ @strongify(self); [self youpaifshowYongNoticeWindow]; }]; }else{ //获取与当前的时间差 NSDate *timeDate = [dateFormatter dateFromString:updateTime]; NSTimeInterval timeInterval = [timeDate timeIntervalSinceNow]; timeInterval = -timeInterval; //超过30天 if (timeInterval>60*60*24) { NSString* dataString = [dateFormatter stringFromDate:newData]; [LCSaveData saveYoungNoticeTime:dataString]; //弹出青少年模式弹窗 [self youpaifshowYongNoticeWindow]; }else{ } } } } //显示设置青少年模式通知 -(void)youpaifshowYongNoticeWindow { YOUPAILPYoungOpenWindow *VC= [[YOUPAILPYoungOpenWindow alloc]init]; VC.vWidth = 313.0f; VC.vHeight = 357.0f; VC.youpaipdelegate = self; VC.isTouchDismiss = YES; [self TFPresentVC:VC completion:^{ }]; } -(void)youpaifshowYoungCloseWindow { YOUPAILPYoungCloseWindow *VC= [[YOUPAILPYoungCloseWindow alloc]init]; VC.vWidth = 313.0f; VC.vHeight = 357.0f; VC.youpaipdelegate = self; VC.isTouchDismiss = NO; [self TFPresentVC:VC completion:^{ }]; } //判断青少年模式状态 -(void)youpaifAdenscentStatus:(void(^)(void))openBlock closed:(void(^)(void))closeBlock{ [LCHttpHelper requestWithURLString:GetAdolescentStatus parameters:nil needToken:YES type:HttpRequestTypePost success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 NSInteger adoleStatus=[dict[@"data"][@"is_set_adolescent"] integerValue]; if(adoleStatus==1) { openBlock(); } else { closeBlock(); } } else { } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.mj_JSONString showtime:1]; [self dismissViewControllerAnimated:YES completion:nil]; }]; } #pragma mark LPYoungOpenDelegate 提示或者关闭弹框的回调 -(void)youpaifyoungSettingPwd{//设置未成年模式的密码 YOUPAILPYoungPwdVC *vc = [[YOUPAILPYoungPwdVC alloc]init]; vc.youpaipdelegate = self; vc.youpaippwdStatus = TFPWDSETTING; [self.navigationController pushViewController:vc animated:YES]; } //忘记密码 -(void)youpaifyoungForgetPwd{ YOUPAILPYoungForgetPWD *vc = [[YOUPAILPYoungForgetPWD alloc]init]; vc.youpaipdelegate = self; [self.navigationController pushViewController:vc animated:YES]; //关闭或打开 发通知 或者回调 /* YOUPAILPYoungPwdVC *vc = [[YOUPAILPYoungPwdVC alloc]init]; vc.pwdStatus = TFPWDCLOSE; [self.navigationController pushViewController:vc animated:YES]; */ } -(void)youpaifyoungClose{ YOUPAILPYoungPwdVC *vc = [[YOUPAILPYoungPwdVC alloc]init]; vc.youpaippwdStatus = TFPWDCLOSE; vc.youpaipdelegate = self; [self.navigationController pushViewController:vc animated:YES]; } #pragma mark 密码输入确认回调 -(void)youpaifswitchYounModel:(NSInteger)isopen{ if(isopen){ [self youpaifshowYoungCloseWindow]; [LCSaveData saveYoungMode:YES]; kAppDelegate.kadolescentStatus =1; }else{ [LCSaveData saveYoungMode:NO]; kAppDelegate.kadolescentStatus = 0; } } @end