// // YOUPAILCNewChatNoticationVC.m // LiveChat // // Created by 张灿 on 2018/8/26. // Copyright © 2018年 caicai. All rights reserved. // #import "YOUPAILCNewChatNoticationVC.h" #import "YOUPAILCCommonSwitchCell.h" @interface YOUPAILCNewChatNoticationVC () @property(nonatomic,strong)UITableView* youpaiptableView; @property(nonatomic,assign)BOOL youpaipnotiFlag; @property(nonatomic,strong)UIButton *openBtn; @property(nonatomic,strong)UIView *bgView; @property(nonatomic,assign)BOOL fate_match; @end @implementation YOUPAILCNewChatNoticationVC - (UITableView *)youpaiptableView{ if (!_youpaiptableView) { _youpaiptableView = [[UITableView alloc]initWithFrame:CGRectMake(0, NavBarHeight, KScreenWidth, KScreenHeight-NavBarHeight) style:UITableViewStylePlain]; _youpaiptableView.showsVerticalScrollIndicator = NO; _youpaiptableView.separatorStyle = UITableViewCellSeparatorStyleNone; _youpaiptableView.backgroundColor = [UIColor whiteColor]; _youpaiptableView.delegate = self; _youpaiptableView.dataSource = self; if (@available(iOS 15.0, *)) { _youpaiptableView.sectionHeaderTopPadding = 0; } } return _youpaiptableView; } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings]; if (UIUserNotificationTypeNone == setting.types) { self.youpaipnotiFlag = NO; }else{ self.youpaipnotiFlag = YES; } [self.youpaiptableView reloadData]; } - (void)viewDidLoad { [super viewDidLoad]; self.title = @"消息通知设置"; [self.view addSubview:self.youpaiptableView]; [self getFateMatch]; // [self setHeaderView]; } -(void)setHeaderView{ UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 27)]; self.youpaiptableView.tableHeaderView = headerView; //bgView UIView *bgView = [UIView new]; self.bgView = bgView; [headerView addSubview:bgView]; [bgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.top.mas_equalTo(0); make.bottom.mas_equalTo(0); }]; bgView.backgroundColor = HexColorFromRGBA(0xFFA68B, 0.06); //title UILabel *titleLabel = [UILabel new]; [bgView addSubview:titleLabel]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(14); make.centerY.mas_equalTo(0); }]; titleLabel.text = @"你未开启通知权限,请在系统权限中开启"; titleLabel.textColor = HexColorFromRGB(0xFFA68B); titleLabel.font = [UIFont systemFontOfSize:12]; //开启按钮 UIButton *openBtn = [UIButton new]; self.openBtn = openBtn; [bgView addSubview:openBtn]; [openBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-14); make.centerY.mas_equalTo(0); }]; [openBtn setTitle:@"去开启" forState:UIControlStateNormal]; [openBtn setTitleColor:HexColorFromRGB(0xFFA68B) forState:UIControlStateNormal];; openBtn.titleLabel.font = [UIFont systemFontOfSize:12]; [openBtn setImage:[UIImage imageNamed:@"vqu_images_others_more"] forState:UIControlStateNormal]; openBtn.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft; [openBtn addTarget:self action:@selector(openBtnClick) forControlEvents:UIControlEventTouchUpInside]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender == 2&&![LCSaveData getWhiteVersion]) { return 3; }else{ return 2; } } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender == 2&&![LCSaveData getWhiteVersion]) { if (section==0||section==1) { return 1; }else{ return 2; } }else{ if (section==0) { return 1; }else{ return 2; } } } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender == 2&&![LCSaveData getWhiteVersion]) { if (section == 0||section==1) { return 49; } return 39; }else{ if (section == 0) { return 49; } return 39; } } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender == 2&&![LCSaveData getWhiteVersion]) { if (section==0||section==1) { return 50; }else { return 0.00001f; } }else{ if (section==0) { return 50; }else { return 0.00001f; } } } //- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ // CGFloat height = 49.0; // if (section == 1) { // height = 39.0; // } // UIView* headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth,height)]; // UILabel* headerLabel = [[UILabel alloc]initWithFrame:CGRectMake(35,height-19,KScreenWidth-35,15)]; // headerLabel.textColor = LCTextGray; // headerLabel.font = LCFont12; // if (section==0) { // headerLabel.text = @"流光花舞未打开时"; // }else{ // headerLabel.text = @"流光花舞打开时"; // } // [headerView addSubview:headerLabel]; // return headerView; //} - (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender == 2&&![LCSaveData getWhiteVersion]) { if (section == 0||section==1) { UIView* footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 51)]; UILabel* txtLabel = [[UILabel alloc]initWithFrame:CGRectMake(14, 0, KScreenWidth-28, 40)]; txtLabel.font = [UIFont systemFontOfSize:12]; txtLabel.textColor = LZA3AABEColor; txtLabel.numberOfLines = 0; if (section==1 && self.youpaipnotiFlag==NO) { txtLabel.text = @"你已在系统中关闭相语欢颜的通知。如需打开,点击上方开关跳转到设置打开“允许通知”"; }else if(section == 1 && self.youpaipnotiFlag == YES){ txtLabel.text = @"您已在系统设置中开启了相语欢颜的通知,如需关闭,请在系统设置-通知中,重新设置消息提醒权限。”"; } if (section == 0) { txtLabel.text =@"开启后,相语欢颜将用大数据为您匹配有缘人,牵线成功会发送缘分消息,关闭后,将不会收到缘分牵线。"; } [footView addSubview:txtLabel]; return footView; }else{ return nil; } }else{ if (section == 0) { UIView* footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 51)]; UILabel* txtLabel = [[UILabel alloc]initWithFrame:CGRectMake(14, 0, KScreenWidth-28, 40)]; txtLabel.font = [UIFont systemFontOfSize:12]; txtLabel.textColor = LZA3AABEColor; txtLabel.numberOfLines = 0; if (section==0 && self.youpaipnotiFlag==NO) { txtLabel.text = @"你已在系统中关闭相语欢颜的通知。如需打开,点击上方开关跳转到设置打开“允许通知”"; }else if(section == 0 && self.youpaipnotiFlag == YES){ txtLabel.text = @"您已在系统设置中开启了相语欢颜的通知,如需关闭,请在系统设置-通知中,重新设置消息提醒权限。”"; } [footView addSubview:txtLabel]; return footView; }else{ return nil; } } } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 45; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ YOUPAILCCommonSwitchCell * cell = [[YOUPAILCCommonSwitchCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"commonSwitchCell"]; if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender == 2&&![LCSaveData getWhiteVersion]) { if (indexPath.section==0) { cell.youpaiprightBtn.hidden = YES; cell.youpaipcommonSwitch.hidden = NO; cell.youpaipcommonSwitch.tag = indexPath.row; cell.youpaipheadLabel.text = @"缘分牵线"; cell.youpaipheadLabel.font = [UIFont systemFontOfSize:15]; if (self.fate_match) { cell.youpaipcommonSwitch.selected = YES; }else{ cell.youpaipcommonSwitch.selected = NO; } [cell.youpaipcommonSwitch addTarget:self action:@selector(youpaifopenFateSwitchValueChange:) forControlEvents:UIControlEventTouchUpInside]; return cell; }else if (indexPath.section==1) { // cell.youpaipheadLabel.text = @"新消息通知"; // cell.youpaipbaseView.layer.cornerRadius = 8; // cell.youpaipbaseView.layer.masksToBounds = YES; // cell.youpaipline.hidden = YES; // cell.youpaiprightBtn.hidden = NO; // cell.youpaipheadLabel.font = [UIFont systemFontOfSize:14]; // cell.youpaipcommonSwitch.hidden = YES; cell.youpaiprightBtn.hidden = YES; cell.youpaipcommonSwitch.hidden = NO; cell.youpaipcommonSwitch.tag = indexPath.row; cell.youpaipheadLabel.text = @"新消息通知"; cell.youpaipheadLabel.font = [UIFont systemFontOfSize:15]; if (self.youpaipnotiFlag) { cell.youpaipcommonSwitch.selected = YES; // cell.youpaipcanSwitch = NO; // // [cell.youpaiprightBtn setTitle:@"已开启" forState:UIControlStateNormal]; // [cell.youpaiprightBtn setTitleColor:HexColorFromRGB(0x9F9DA5) forState:UIControlStateNormal]; }else{ // cell.youpaipcanSwitch = YES; cell.youpaipcommonSwitch.selected = NO; // [cell.youpaiprightBtn setTitle:@"去开启" forState:UIControlStateNormal]; // [cell.youpaiprightBtn setTitleColor:HexColorFromRGB(0xF4003F) forState:UIControlStateNormal]; } [cell.youpaipcommonSwitch addTarget:self action:@selector(youpaifopenNotiSwitchValueChange:) forControlEvents:UIControlEventTouchUpInside]; return cell; } else if (indexPath.section==2){ cell.youpaiprightBtn.hidden = YES; cell.youpaipcommonSwitch.hidden = NO; cell.youpaipcommonSwitch.tag = indexPath.row; if (indexPath.row==0) { cell.youpaipheadLabel.text = @"声音"; cell.youpaipheadLabel.font = [UIFont systemFontOfSize:15]; cell.youpaipcommonSwitch.selected = [LCSaveData getIMMsgVoice]; [cell.youpaipcommonSwitch addTarget:self action:@selector(youpaifvoiceSwitchValueChange:) forControlEvents:UIControlEventTouchUpInside]; // [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:cell.youpaipbaseView size:CGSizeMake(8,8)]; }else{ cell.youpaipheadLabel.text = @"振动"; cell.youpaipheadLabel.font = [UIFont systemFontOfSize:15]; cell.youpaipcommonSwitch.selected = [LCSaveData getIMMsgShake]; [cell.youpaipcommonSwitch addTarget:self action:@selector(youpaifshakeSwitchValueChange:) forControlEvents:UIControlEventTouchUpInside]; cell.youpaipline.hidden = YES; // [LCTools clipCorner:UIRectCornerBottomLeft|UIRectCornerBottomRight View:cell.youpaipbaseView size:CGSizeMake(8,8)]; } } return cell; }else{ if (indexPath.section==0) { // cell.youpaipheadLabel.text = @"新消息通知"; // cell.youpaipbaseView.layer.cornerRadius = 8; // cell.youpaipbaseView.layer.masksToBounds = YES; // cell.youpaipline.hidden = YES; // cell.youpaiprightBtn.hidden = NO; // cell.youpaipheadLabel.font = [UIFont systemFontOfSize:14]; // cell.youpaipcommonSwitch.hidden = YES; cell.youpaiprightBtn.hidden = YES; cell.youpaipcommonSwitch.hidden = NO; cell.youpaipcommonSwitch.tag = indexPath.row; cell.youpaipheadLabel.text = @"新消息通知"; cell.youpaipheadLabel.font = [UIFont systemFontOfSize:15]; if (self.youpaipnotiFlag) { cell.youpaipcommonSwitch.selected = YES; // cell.youpaipcanSwitch = NO; // // [cell.youpaiprightBtn setTitle:@"已开启" forState:UIControlStateNormal]; // [cell.youpaiprightBtn setTitleColor:HexColorFromRGB(0x9F9DA5) forState:UIControlStateNormal]; }else{ // cell.youpaipcanSwitch = YES; cell.youpaipcommonSwitch.selected = NO; // [cell.youpaiprightBtn setTitle:@"去开启" forState:UIControlStateNormal]; // [cell.youpaiprightBtn setTitleColor:HexColorFromRGB(0xF4003F) forState:UIControlStateNormal]; } [cell.youpaipcommonSwitch addTarget:self action:@selector(youpaifopenNotiSwitchValueChange:) forControlEvents:UIControlEventTouchUpInside]; return cell; } else if (indexPath.section==1){ cell.youpaiprightBtn.hidden = YES; cell.youpaipcommonSwitch.hidden = NO; cell.youpaipcommonSwitch.tag = indexPath.row; if (indexPath.row==0) { cell.youpaipheadLabel.text = @"声音"; cell.youpaipheadLabel.font = [UIFont systemFontOfSize:15]; cell.youpaipcommonSwitch.selected = [LCSaveData getIMMsgVoice]; [cell.youpaipcommonSwitch addTarget:self action:@selector(youpaifvoiceSwitchValueChange:) forControlEvents:UIControlEventTouchUpInside]; // [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:cell.youpaipbaseView size:CGSizeMake(8,8)]; }else{ cell.youpaipheadLabel.text = @"振动"; cell.youpaipheadLabel.font = [UIFont systemFontOfSize:15]; cell.youpaipcommonSwitch.selected = [LCSaveData getIMMsgShake]; [cell.youpaipcommonSwitch addTarget:self action:@selector(youpaifshakeSwitchValueChange:) forControlEvents:UIControlEventTouchUpInside]; cell.youpaipline.hidden = YES; // [LCTools clipCorner:UIRectCornerBottomLeft|UIRectCornerBottomRight View:cell.youpaipbaseView size:CGSizeMake(8,8)]; } } return cell; } return nil; } -(void)openBtnClick{ } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section==1) { if (self.youpaipnotiFlag == NO) { NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; if ([[UIApplication sharedApplication] canOpenURL:url]) { [[UIApplication sharedApplication] openURL:url]; } } } } - (void)youpaifopenNotiSwitchValueChange:(UIButton*)switchView{ NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; if ([[UIApplication sharedApplication] canOpenURL:url]) { [[UIApplication sharedApplication] openURL:url]; } } - (void)youpaifvoiceSwitchValueChange:(UIButton*)switchView{ switchView.selected = !switchView.selected; if (switchView.selected==YES) { [LCSaveData saveIMMsgVoice:YES]; }else{ [LCSaveData saveIMMsgVoice:NO]; } } - (void)youpaifshakeSwitchValueChange:(UIButton*)switchView{ switchView.selected = !switchView.selected; if (switchView.selected==YES) { [LCSaveData saveIMMsgShake:YES]; }else{ [LCSaveData saveIMMsgShake:NO]; } } -(void)getFateMatch{ [LCHttpHelper requestWithURLString:Mine_getFateMatch parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 // 缘分牵线 1开启 0关闭 self.fate_match =[dict[@"data"][@"fate_match"] intValue]; NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:0]; [self.youpaiptableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationNone]; } } failure:^(NSError *error) { }]; } -(void)youpaifopenFateSwitchValueChange:(UIButton*)sender{ sender.selected = !sender.selected; NSInteger fateStatus = sender.selected ==YES? 1:0; [LCHttpHelper requestWithURLString:Mine_setFateMatch parameters:@{@"fate_match":@(fateStatus)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 // 缘分牵线 1开启 0关闭 self.fate_match = fateStatus; NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:0]; [self.youpaiptableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationNone]; } } failure:^(NSError *error) { }]; } @end