// // ViewController.m // xplan-ios // // Created by zu on 2021/8/31. // #import ///Third #import #import #import #import ///Tool #import "XPMacro.h" #import "ThemeColor.h" #import "UIImage+Utils.h" #import "NSObject+MJExtension.h" #import "XCHUDTool.h" #import "AccountInfoStorage.h" #import "TTPopup.h" #import "XPConstant.h" #import "XPRoomMiniManager.h" #import "ClientConfig.h" #import "RtcManager.h" #import "XCCurrentVCStackManager.h" #import "Api+Home.h" #import "XPConstant.h" ///Model #import "AccountModel.h" #import "RoomInfoModel.h" #import "AttachmentModel.h" #import "NobleLevelUpModel.h" #import "XPMineVisitorUnReadModel.h" #import "InviteUserInfoModel.h" #import "NewUserGreetModel.h" #import "FindNewGreetMessageModel.h" #import "XPTabAnchorCardModel.h" #import "FirstRechargeModel.h" ///VC #import "TabbarViewController.h" #import "BaseViewController.h" #import "LoginViewController.h" #import "BaseNavigationController.h" #import "LoginBindPhoneViewController.h" #import "LoginFullInfoViewController.h" #import "XplanFBFlutterViewContainer.h" #import "XPMineViewController.h" #import "SessionListViewController.h" #import "XPHomeViewController.h" #import "XPMiniRoomView.h" #import "XPTeenagerAlertView.h" #import "XPRoomViewController.h" #import "XPNobleUpgradeLevelView.h" #import "XPNewUserGreetRoomAlertView.h" #import "XPSessionFindNewAlertView.h" #import "XPHomeLivesViewController.h" #import "XPNewUserRechargeViewController.h" #import "XPAnchorCardView.h" #import "XPNewUserRechargeSucessView.h" #import "XPTaskCompleteTipView.h" #import "XPWebViewController.h" #import "XPMineUserInfoViewController.h" ///Present #import "MainPresenter.h" #import "MainProtocol.h" #import "RoomHostDelegate.h" UIKIT_EXTERN NSString * kUserCompleteInfoFinishKey; NSString * const kUserFirstLoginKey = @"kUserFirstLoginKey"; NSString * const kHadLaunchApp = @"kHadLaunchApp"; NSString * const kLastShowAnchorCardTime = @"kLastShowAnchorCardTime"; UIKIT_EXTERN NSString * kHomeMoreScrollPageKey; UIKIT_EXTERN NSString * kNewUserRechargeKey; UIKIT_EXTERN NSString *kTabShowAnchorCardKey; @interface TabbarViewController () @property (nonatomic, strong) MainPresenter *presenter; ///房间最小化 @property (nonatomic,strong) XPMiniRoomView *roomMineView; ///邀请码 @property (nonatomic,copy) NSString *inviteCode; ///需要显示新用户充值优惠弹窗 @property (nonatomic, assign) BOOL needShowNewUserRecharge; ///需要展示主播卡片(首次) @property (nonatomic, assign) BOOL needShowAnchorCard; ///延迟弹出主播卡片 @property (nonatomic, assign) BOOL delayShowAnchorCard; ///主播卡片 @property (nonatomic, strong) XPAnchorCardView *anchorCardView; ///任务完成提示 @property (nonatomic, strong) XPTaskCompleteTipView *taskTipView; @end @implementation TabbarViewController - (void)viewDidLoad { [super viewDidLoad]; [self configTheme]; [self initTabs:NO]; [[ClientConfig shareConfig] clientInit]; [[NIMSDK sharedSDK].loginManager addDelegate:self]; [[NIMSDK sharedSDK].chatManager addDelegate:self]; [[NIMSDK sharedSDK].systemNotificationManager addDelegate:self]; [self.presenter juliandAdCallBackApi]; [self.view addSubview:self.roomMineView]; [[NSNotificationCenter defaultCenter] addObserverForName:kRoomMiniNotificationKey object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) { [self configRoomMiniNView:note.userInfo]; }]; [[NSNotificationCenter defaultCenter] addObserverForName:kUserCompleteInfoFinishKey object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) { [self completeUserInfoFinish:note.object]; }]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recommendMoreNotification:) name:kHomeMoreScrollPageKey object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showNewUserRecharge) name:kNewUserRechargeKey object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showAnchorCardKey:) name:kTabShowAnchorCardKey object:nil]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:YES animated:YES]; [self.presenter autoLogin]; if ([XPRoomMiniManager shareManager].getRoomInfo == nil) { [self.roomMineView hiddenRoomMiniView]; } } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; self.delayShowAnchorCard = NO; [self.anchorCardView removeFromSuperview]; self.anchorCardView = nil; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; if (self.needShowNewUserRecharge) { self.needShowNewUserRecharge = NO; XPNewUserRechargeViewController *vc = [[XPNewUserRechargeViewController alloc] initWithNavigation:self.selectedViewController.navigationController]; vc.hadAnimate = YES; [self.selectedViewController.navigationController presentViewController:vc animated:YES completion:nil]; } if ([self hadLaunchApp] && (self.selectedIndex == 0 | self.selectedIndex == 1) && [self canShowAnchorCard]) { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ if (self.view.window && self.isViewLoaded) { [self.presenter getAnchorCardInfo]; } }); } if (self.needShowAnchorCard && !self.delayShowAnchorCard) { [self.presenter getAnchorCardInfo]; [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kHadLaunchApp];///第一次弹主播卡片 [[NSUserDefaults standardUserDefaults] synchronize]; } } - (MainPresenter *)presenter { if (_presenter == nil) { _presenter = [[MainPresenter alloc] init]; [_presenter attatchView:self]; } return _presenter; } /** 登录成功(通过token且换取ticket后)。 1. 登录云信。 2. 获取用户信息。 3. 其实目前多余回调V层,可以在P层里自行做这个逻辑。 */ - (void)autoLoginSuccess { [self.presenter loginNIM]; [self.presenter getUserInfo]; ///登录成功之后 在验证是否有漏单的行为 [self.presenter checkTranscation]; if (self.inviteCode && self.inviteCode.length > 0) { ///邀请码进房 [self.presenter checkInviteUserInfo:self.inviteCode]; } } /// 获取用户信息后检查:1、是否绑定手机号;2、是否需要完善用户信息。 /// 该逻辑仅在刷新ticket后执行一次。 /// 当前服务端接口是有未完善信息的全局拦截的,在BaseMvpPresenter里会触发1415去完善用户信息。 - (void)getUserInfoSuccess:(UserInfoModel *)userInfo { if (!userInfo.isBindPhone && [ClientConfig shareConfig].iosPhoneBind) { LoginBindPhoneViewController * bindPhoneVC = [[LoginBindPhoneViewController alloc] init]; BaseNavigationController * nav = [[BaseNavigationController alloc] initWithRootViewController:bindPhoneVC]; nav.modalPresentationStyle = UIModalPresentationFullScreen; [self.navigationController presentViewController:nav animated:YES completion:nil]; return; } if (userInfo.nick == nil || userInfo.avatar == nil) { [self completeUserInfo]; return; } [self initTabs:YES]; if (self.inviteCode.length <= 0) { [self initQuickEnterRoom]; } if (self.inviteCode) { self.inviteCode = nil; } [self showTeenagerAlertView:userInfo]; } - (void)checkInviteUserInfoSuccess:(InviteUserInfoModel *)inviteInfo { if (inviteInfo && inviteInfo.isInRoom) { [XPRoomViewController openRoom:inviteInfo.roomUid fromNick:inviteInfo.inviteNick fromType:inviteInfo.fromType fromUid:inviteInfo.inviteUid viewController:self]; } else { //不在房间 ///新用户打招呼引导 [self.presenter getNewUserGreetInfo]; } } - (void)getNewUserGreetInfoSucces:(NewUserGreetModel *)greetInfo { NSString * key = [NSString stringWithFormat:@"%@_%@", kUserFirstLoginKey, [AccountInfoStorage instance].getUid]; [[NSUserDefaults standardUserDefaults] setBool:YES forKey:key]; if (greetInfo.sayHello) { XPNewUserGreetRoomAlertView * alertView = [[XPNewUserGreetRoomAlertView alloc] init]; alertView.greetInfo = greetInfo; alertView.currentVC = self; TTPopupService * config = [[TTPopupService alloc] init]; config.contentView = alertView; config.shouldDismissOnBackgroundTouch = NO; config.maskBackgroundAlpha = 0.8; [TTPopup popupWithConfig:config]; } else { [self.presenter getShortCutRecommendRoom]; } } - (void)getShortCutRecommendRoomSuccces:(NSString *)roomUid { if (roomUid.length > 0) { [XPRoomViewController openRoom:roomUid viewController:self]; } } #pragma mark - BaseMvpProtocol - (void)tokenInvalid { LoginViewController *lvc = [[LoginViewController alloc] init]; BaseNavigationController * nav = [[BaseNavigationController alloc] initWithRootViewController:lvc]; nav.modalPresentationStyle = UIModalPresentationFullScreen; [self.navigationController presentViewController:nav animated:YES completion:nil]; } - (void)completeUserInfo { LoginFullInfoViewController * bindPhoneVC = [[LoginFullInfoViewController alloc] init]; BaseNavigationController * nav = [[BaseNavigationController alloc] initWithRootViewController:bindPhoneVC]; nav.modalPresentationStyle = UIModalPresentationFullScreen; [self.navigationController presentViewController:nav animated:YES completion:nil]; } ///获取主播卡片信息成功 - (void)getAnchorCardInfoSuccess:(XPTabAnchorCardModel *)cardInfo { if (!self.anchorCardView.superview && cardInfo && self.isViewLoaded && self.view.window) { self.anchorCardView.frame = CGRectMake(0, -90-kStatusBarHeight, KScreenWidth, 90); [UIView animateWithDuration:0.5 animations:^{ self.anchorCardView.frame = CGRectMake(0, kStatusBarHeight, KScreenWidth, 90); } completion:^(BOOL finished) { if (finished) { [self shakeAction]; } }]; long time = (long)([[NSDate date] timeIntervalSince1970]*1000); [[NSUserDefaults standardUserDefaults] setObject:@(time) forKey:kLastShowAnchorCardTime]; [[NSUserDefaults standardUserDefaults] synchronize]; self.anchorCardView.cardInfo = cardInfo; [self.view addSubview:self.anchorCardView]; UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleAnchorCardSwipeFrom:)]; [recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)]; [self.anchorCardView addGestureRecognizer:recognizer]; } } ///主播卡片震动动画 - (void)shakeAction { // 晃动次数 static int numberOfShakes = 4; // 晃动幅度(相对于总宽度) static float vigourOfShake = 0.04f; // 晃动延续时常(秒) static float durationOfShake = 0.5f; CAKeyframeAnimation *shakeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; //关键帧(点) CGPoint layerPosition = self.anchorCardView.layer.position; // 起始点 NSValue *value1 = [NSValue valueWithCGPoint:self.anchorCardView.layer.position]; // 关键点数组 NSMutableArray *values = [[NSMutableArray alloc] initWithObjects:value1, nil]; for (int i = 0; i 1) { [[[XCCurrentVCStackManager shareManager] getCurrentVC].navigationController popToRootViewControllerAnimated:YES]; } if ([[UIApplication sharedApplication].delegate.window.rootViewController isKindOfClass:[UITabBarController class]]) { UITabBarController *tabVC = (UITabBarController *)[UIApplication sharedApplication].delegate.window.rootViewController; if (tabVC.selectedViewController.navigationController) { [tabVC.selectedViewController.navigationController popToRootViewControllerAnimated:YES]; } dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [tabVC setSelectedIndex:0]; }); } }]; }else { //不是被present出来的 就有可能是rootvc或者是被push出来的 所以要判断nav是不是只有一个vc 如果有多个就pop if ([[XCCurrentVCStackManager shareManager] getCurrentVC].navigationController.viewControllers.count > 1) { [[[XCCurrentVCStackManager shareManager] getCurrentVC].navigationController popToRootViewControllerAnimated:YES]; } if ([[UIApplication sharedApplication].delegate.window.rootViewController isKindOfClass:[UITabBarController class]]) { UITabBarController *tabVC = (UITabBarController *)[UIApplication sharedApplication].delegate.window.rootViewController; if (tabVC.selectedViewController) { if ([tabVC.selectedViewController isKindOfClass:[UINavigationController class]]) { [tabVC.selectedViewController popToRootViewControllerAnimated:YES]; } else { [tabVC.selectedViewController.navigationController popToRootViewControllerAnimated:YES]; } dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [tabVC setSelectedIndex:0]; }); } } } if ([XPRoomMiniManager shareManager].getRoomInfo) { [[RtcManager instance] exitRoom]; [[NIMSDK sharedSDK].chatroomManager exitChatroom:[NSString stringWithFormat:@"%ld", [XPRoomMiniManager shareManager].getRoomInfo.roomId] completion:nil]; [self.roomMineView hiddenRoomMiniView]; } [self.presenter logout]; } #pragma mark - NIMChatManagerDelegate - (void)onRecvMessages:(NSArray *)messages { for (NIMMessage * message in messages) { if (message.session.sessionType == NIMSessionTypeP2P) { if(message.messageType == NIMMessageTypeCustom) { NIMCustomObject *obj = (NIMCustomObject *)message.messageObject; if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) { AttachmentModel * attachment = obj.attachment; if (attachment.first == CustomMessageType_FindNew && attachment.second == Custom_Message_Find_New_Greet_New_User) { FindNewGreetMessageModel * greetInfo = [FindNewGreetMessageModel modelWithDictionary:attachment.data]; if (greetInfo.uid.integerValue != [AccountInfoStorage instance].getUid.integerValue) { [TTPopup dismiss]; XPSessionFindNewAlertView * alertView = [[XPSessionFindNewAlertView alloc] init]; alertView.userInfo = greetInfo; TTPopupService *service = [[TTPopupService alloc] init]; service.contentView = alertView; service.shouldDismissOnBackgroundTouch = NO; service.style = TTPopupStyleAlert; [TTPopup popupWithConfig:service]; } } } } } } } - (void)configTheme { self.view.backgroundColor = [ThemeColor tabbarViewColor]; [[UITabBar appearance] setBackgroundImage:[UIImage imageWithColor:[ThemeColor tabbarViewColor] size:CGSizeMake(KScreenWidth, kTabBarHeight)]]; [[UITabBar appearance] setShadowImage:[[UIImage alloc]init]]; if (@available(iOS 10.0, *)) { [[UITabBar appearance] setUnselectedItemTintColor:[ThemeColor tabbarNormalColor]]; } } - (void)initTabs:(BOOL)logined { self.viewControllers = nil; NSArray *normalImageNames = @[@"tab_gameHome_normal",@"tab_live_normal",@"tab_message_normal", @"tab_mine_normal"]; NSArray *selectImageNames = @[@"tab_gameHome_selected",@"tab_live_selected",@"tab_message_selected", @"tab_mine_selected"]; NSArray *tabLabel = @[@"派对",@"直播",@"消息", @"我的"]; UIViewController *game; UIViewController *msg; UIViewController *me; UIViewController * home; if (logined) { XplanFBFlutterViewContainer *fvcGame = XplanFBFlutterViewContainer.new; #ifdef DEBUG [fvcGame setName:@"debug" uniqueId:nil params:nil]; #else [fvcGame setName:@"/" uniqueId:nil params:nil]; #endif game = [[XPHomeLivesViewController alloc] init]; msg = [[SessionListViewController alloc] init]; me = [[XPMineViewController alloc] init]; home = [[XPHomeViewController alloc] init]; } else { game = [[BaseViewController alloc]init]; msg = [[SessionListViewController alloc]init]; me = [[BaseViewController alloc]init]; home = [[BaseViewController alloc] init]; } [self createTabBarItem:home title:tabLabel[0] image:normalImageNames[0] selectedImage:selectImageNames[0]]; [self createTabBarItem:game title:tabLabel[1] image:normalImageNames[1] selectedImage:selectImageNames[1]]; [self createTabBarItem:msg title:tabLabel[2] image:normalImageNames[2] selectedImage:selectImageNames[2]]; [self createTabBarItem:me title:tabLabel[3] image:normalImageNames[3] selectedImage:selectImageNames[3]]; self.viewControllers = @[home,game,msg,me]; self.selectedIndex = 0; } - (BaseNavigationController *)createTabBarItem:(UIViewController *)itemVc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage{ itemVc.title = title; itemVc.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; itemVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; [itemVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[ThemeColor mainTextColor]} forState:UIControlStateSelected]; [itemVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[ThemeColor tabbarNormalColor]} forState:UIControlStateNormal]; BaseNavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:itemVc]; return nav; } - (void)showSuccessToast:(NSString *)msg { [XCHUDTool showSuccessWithMessage:msg]; } - (void)showErrorToast:(NSString *)msg { [XCHUDTool showErrorWithMessage:msg]; } - (void)showLoading { [XCHUDTool showLoading]; } - (void)hideHUD { [XCHUDTool hideHUD]; } #pragma mark - 房间最小化 - (void)configRoomMiniNView:(NSDictionary *)dic { UserInfoModel * userInfo = [UserInfoModel modelWithDictionary:dic[@"userInfo"]]; RoomInfoModel * roomInfo = [RoomInfoModel modelWithDictionary:dic[@"roomInfo"]]; NSMutableDictionary * microQueue = dic[@"microQueue"]; [self.roomMineView configRoomMiniView:roomInfo userInfo:userInfo micQueue:microQueue]; } #pragma mark - 青少年模式 - (void)showTeenagerAlertView:(UserInfoModel *)userInfo { if (!userInfo || userInfo.uid <=0) return; ///用户信息为空 不处理 if (userInfo.parentMode) return;// 开启了青少年模式的话 就不用处理 NSString * teenagerKey = [NSString stringWithFormat:@"%@_%ld", kTeenagerAlertDatekey, userInfo.uid]; NSDate * oldDate = [[NSUserDefaults standardUserDefaults] objectForKey:teenagerKey]; BOOL isSameDay = [[NSCalendar currentCalendar] isDateInToday:oldDate]; if (isSameDay) return; XPTeenagerAlertView * teenagerView = [[XPTeenagerAlertView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth - 45 * 2, 260)]; teenagerView.controller = self; [TTPopup popupView:teenagerView style:TTPopupStyleAlert]; [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:teenagerKey]; } #pragma mark - 快捷进房 - (void)initQuickEnterRoom { NSString * key = [NSString stringWithFormat:@"%@_%@", kUserFirstLoginKey, [AccountInfoStorage instance].getUid]; BOOL isNotFirstLogin = [[NSUserDefaults standardUserDefaults] boolForKey:key]; if (isNotFirstLogin) { [self.presenter getShortCutRecommendRoom]; } else { ///新用户 [self.presenter getNewUserGreetInfo]; } } ///跳转优先级 闪屏→linkedMe→邀请码→新用户打招呼引导→渠道指定房间 - (void)completeUserInfoFinish:(NSString *)inviteCode { self.inviteCode = inviteCode; } #pragma mark -NIMSystemNotificationManagerDelegate - (void)onReceiveCustomSystemNotification:(NIMCustomSystemNotification *)notification { if (notification.receiverType == NIMSessionTypeP2P) { if (notification.content != nil) { NSData *jsonData = [notification.content dataUsingEncoding:NSUTF8StringEncoding]; NSError *err; NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err]; if(err) { NSLog(@"json解析失败:%@",err); return; } if ([dic[@"first"] intValue] == CustomMessageType_Noble_VIP && [dic[@"second"] intValue] == Custom_Message_Sub_Noble_LevelUp_User) { // 用户贵族升级 if ([dic isKindOfClass:[NSDictionary class]]) { [self receiveNobleLevelUp:dic]; } } else if ([dic[@"first"] integerValue] == CustomMessageType_First_VisitorRecord){//访客记录数量更新提示 AttachmentModel *attachment = [AttachmentModel modelWithJSON:notification.content]; XPMineVisitorUnReadModel *model = [XPMineVisitorUnReadModel modelWithJSON:attachment.data]; if ([model isKindOfClass:XPMineVisitorUnReadModel.class]) { [[NSNotificationCenter defaultCenter] postNotificationName:kVisitorUnReadCountNotificationKey object:model]; } } else if ([dic[@"first"] intValue] == CustomMessageType_First_Recharge_Reward && [dic[@"second"] intValue] == Custom_Message_Sub_New_User_Recharge_Reward) { // 新用户充值优惠成功 if ([dic isKindOfClass:[NSDictionary class]]) { FirstRechargeModel *model = [FirstRechargeModel modelWithDictionary:dic[@"data"]]; XPNewUserRechargeSucessView * firstRechargeView= [[XPNewUserRechargeSucessView alloc] init]; firstRechargeView.rechargeInfo = model; [TTPopup popupView:firstRechargeView style:TTPopupStyleAlert]; } } else if ([dic[@"first"] intValue] == CustomMessageType_Task_Complete && [dic[@"second"] intValue] == Custom_Message_Sub_TaskComplete) {///任务完成提醒 if ([dic isKindOfClass:[NSDictionary class]]) { NSDictionary *dict = dic[@"data"]; [self handleActivityTaskTip:dict[@"taskCompleteMsg"] url:dic[@"taskUrl"]]; } } } } } - (void)receiveNobleLevelUp:(NSDictionary *)data { XPNobleUpgradeLevelView *view = [[XPNobleUpgradeLevelView alloc] initWithFrame:CGRectMake(0, 0, 300, 285 + 22 + 44)]; NobleLevelUpModel *receiveInfo = [NobleLevelUpModel modelWithDictionary:data[@"data"]]; view.levelUpInfo = receiveInfo; [TTPopup popupView:view style:TTPopupStyleAlert]; } #pragma mark - Event Response - (void)recommendMoreNotification:(NSNotification *)notification { if ([notification.object[@"section"] intValue] == 3) { self.selectedIndex = 1; } } #pragma mark - 主播卡片弹窗 //新用户专享充值弹窗 - (void)showNewUserRecharge { self.needShowNewUserRecharge = YES; } ///展示主播卡片 - (void)showAnchorCardKey:(NSNotification *)noti { NSDictionary * dic = noti.object; self.delayShowAnchorCard = [[dic objectForKey:@"delayShow"] boolValue]; self.needShowAnchorCard = YES; } ///判断第二次启动时弹出主播卡片 - (BOOL)hadLaunchApp { return [[NSUserDefaults standardUserDefaults] valueForKey:kHadLaunchApp]; } - (BOOL)canShowAnchorCard { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSNumber *lastTime = [defaults objectForKey:kLastShowAnchorCardTime]; if ([lastTime longValue] < 1) { return NO; } NSDate *datenow = [NSDate date];//现在时间 long time2 = (long)([datenow timeIntervalSince1970]*1000); long aTime = (time2 - [lastTime longValue]) / 1000; if (aTime > 15*60) { return YES; } else { return NO; } } #pragma mark - 活动任务完成提示 - (void)handleActivityTaskTip:(NSString *)msg url:(NSString *)url { if (!self.taskTipView.superview && url.length) { [self.view addSubview:self.taskTipView]; self.taskTipView.desc = msg; self.taskTipView.url = url; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(jumpToTask:)]; [self.taskTipView addGestureRecognizer:tap]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ if (self.taskTipView.superview) { [self.taskTipView removeFromSuperview]; } self.taskTipView = nil; }); } } - (void)jumpToTask:(UITapGestureRecognizer *)ges { XPWebViewController * webVC =[[XPWebViewController alloc] init]; webVC.url = self.taskTipView.url; [self.selectedViewController.navigationController pushViewController:webVC animated:YES]; if (self.taskTipView.superview) { [self.taskTipView removeFromSuperview]; } self.taskTipView = nil; } #pragma mark - XPAnchorCardViewDelegate - (void)xPAnchorCardViewEnterRoom:(NSString *)roomUid { if (roomUid) { [self.anchorCardView removeFromSuperview]; self.anchorCardView = nil; self.needShowAnchorCard = NO; [XPRoomViewController openRoom:roomUid viewController:self]; } else { [UIView animateWithDuration:0.5 animations:^{ self.anchorCardView.frame = CGRectMake(0, -90-kStatusBarHeight, KScreenWidth, 90); } completion:^(BOOL finished) { [self.anchorCardView removeFromSuperview]; self.anchorCardView = nil; self.needShowAnchorCard = NO; }]; } } - (void)xPAnchorCardViewClickAvatar:(NSString *)uid { if (uid.length) { XPMineUserInfoViewController * userInfoVC = [[XPMineUserInfoViewController alloc] init]; userInfoVC.uid = uid.integerValue; [self.selectedViewController.navigationController pushViewController:userInfoVC animated:YES]; [self.anchorCardView removeFromSuperview]; self.anchorCardView = nil; self.needShowAnchorCard = NO; } else { [self.anchorCardView removeFromSuperview]; self.anchorCardView = nil; self.needShowAnchorCard = NO; } } - (void)handleAnchorCardSwipeFrom:(UISwipeGestureRecognizer *)recognizer{ if(recognizer.direction == UISwipeGestureRecognizerDirectionUp) { [UIView animateWithDuration:0.5 animations:^{ self.anchorCardView.frame = CGRectMake(0, -90-kStatusBarHeight, KScreenWidth, 90); } completion:^(BOOL finished) { [self.anchorCardView removeFromSuperview]; self.anchorCardView = nil; self.needShowAnchorCard = NO; }]; } } #pragma mark - Getters And Setters - (XPMiniRoomView *)roomMineView { if (!_roomMineView) { _roomMineView = [[XPMiniRoomView alloc] init]; _roomMineView.controller = self; _roomMineView.hidden = YES; } return _roomMineView; } - (XPAnchorCardView *)anchorCardView { if (!_anchorCardView) { _anchorCardView = [[XPAnchorCardView alloc] init]; _anchorCardView.delegate = self; } return _anchorCardView; } - (XPTaskCompleteTipView *)taskTipView { if (!_taskTipView) { _taskTipView = [[XPTaskCompleteTipView alloc] initWithFrame:CGRectMake(0, KScreenHeight - kSafeAreaBottomHeight-60-20, KScreenWidth, 20)]; } return _taskTipView; } @end