YOUPAILCNewChatNoticationVC.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. //
  2. // YOUPAILCNewChatNoticationVC.m
  3. // LiveChat
  4. //
  5. // Created by 张灿 on 2018/8/26.
  6. // Copyright © 2018年 caicai. All rights reserved.
  7. //
  8. #import "YOUPAILCNewChatNoticationVC.h"
  9. #import "YOUPAILCCommonSwitchCell.h"
  10. @interface YOUPAILCNewChatNoticationVC ()<UITableViewDataSource,UITableViewDelegate>
  11. @property(nonatomic,strong)UITableView* youpaiptableView;
  12. @property(nonatomic,assign)BOOL youpaipnotiFlag;
  13. @property(nonatomic,strong)UIButton *openBtn;
  14. @property(nonatomic,strong)UIView *bgView;
  15. @property(nonatomic,assign)BOOL fate_match;
  16. @end
  17. @implementation YOUPAILCNewChatNoticationVC
  18. - (UITableView *)youpaiptableView{
  19. if (!_youpaiptableView) {
  20. _youpaiptableView = [[UITableView alloc]initWithFrame:CGRectMake(0, NavBarHeight, KScreenWidth, KScreenHeight-NavBarHeight) style:UITableViewStylePlain];
  21. _youpaiptableView.showsVerticalScrollIndicator = NO;
  22. _youpaiptableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  23. _youpaiptableView.backgroundColor = [UIColor whiteColor];
  24. _youpaiptableView.delegate = self;
  25. _youpaiptableView.dataSource = self;
  26. if (@available(iOS 15.0, *)) {
  27. _youpaiptableView.sectionHeaderTopPadding = 0;
  28. }
  29. }
  30. return _youpaiptableView;
  31. }
  32. - (void)viewWillAppear:(BOOL)animated{
  33. [super viewWillAppear:animated];
  34. UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
  35. if (UIUserNotificationTypeNone == setting.types) {
  36. self.youpaipnotiFlag = NO;
  37. }else{
  38. self.youpaipnotiFlag = YES;
  39. }
  40. [self.youpaiptableView reloadData];
  41. }
  42. - (void)viewDidLoad {
  43. [super viewDidLoad];
  44. self.title = @"消息通知设置";
  45. [self.view addSubview:self.youpaiptableView];
  46. [self getFateMatch];
  47. // [self setHeaderView];
  48. }
  49. -(void)setHeaderView{
  50. UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 27)];
  51. self.youpaiptableView.tableHeaderView = headerView;
  52. //bgView
  53. UIView *bgView = [UIView new];
  54. self.bgView = bgView;
  55. [headerView addSubview:bgView];
  56. [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.left.mas_equalTo(0);
  58. make.right.mas_equalTo(0);
  59. make.top.mas_equalTo(0);
  60. make.bottom.mas_equalTo(0);
  61. }];
  62. bgView.backgroundColor = HexColorFromRGBA(0xFFA68B, 0.06);
  63. //title
  64. UILabel *titleLabel = [UILabel new];
  65. [bgView addSubview:titleLabel];
  66. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  67. make.left.mas_equalTo(14);
  68. make.centerY.mas_equalTo(0);
  69. }];
  70. titleLabel.text = @"你未开启通知权限,请在系统权限中开启";
  71. titleLabel.textColor = HexColorFromRGB(0xFFA68B);
  72. titleLabel.font = [UIFont systemFontOfSize:12];
  73. //开启按钮
  74. UIButton *openBtn = [UIButton new];
  75. self.openBtn = openBtn;
  76. [bgView addSubview:openBtn];
  77. [openBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.right.mas_equalTo(-14);
  79. make.centerY.mas_equalTo(0);
  80. }];
  81. [openBtn setTitle:@"去开启" forState:UIControlStateNormal];
  82. [openBtn setTitleColor:HexColorFromRGB(0xFFA68B) forState:UIControlStateNormal];;
  83. openBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  84. [openBtn setImage:[UIImage imageNamed:@"vqu_images_others_more"] forState:UIControlStateNormal];
  85. openBtn.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
  86. [openBtn addTarget:self action:@selector(openBtnClick) forControlEvents:UIControlEventTouchUpInside];
  87. }
  88. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  89. if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender == 2&&![LCSaveData getWhiteVersion]) {
  90. return 3;
  91. }else{
  92. return 2;
  93. }
  94. }
  95. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  96. if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender == 2&&![LCSaveData getWhiteVersion]) {
  97. if (section==0||section==1) {
  98. return 1;
  99. }else{
  100. return 2;
  101. }
  102. }else{
  103. if (section==0) {
  104. return 1;
  105. }else{
  106. return 2;
  107. }
  108. }
  109. }
  110. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  111. if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender == 2&&![LCSaveData getWhiteVersion]) {
  112. if (section == 0||section==1) {
  113. return 49;
  114. }
  115. return 39;
  116. }else{
  117. if (section == 0) {
  118. return 49;
  119. }
  120. return 39;
  121. }
  122. }
  123. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  124. if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender == 2&&![LCSaveData getWhiteVersion]) {
  125. if (section==0||section==1) {
  126. return 50;
  127. }else {
  128. return 0.00001f;
  129. }
  130. }else{
  131. if (section==0) {
  132. return 50;
  133. }else {
  134. return 0.00001f;
  135. }
  136. }
  137. }
  138. //- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  139. // CGFloat height = 49.0;
  140. // if (section == 1) {
  141. // height = 39.0;
  142. // }
  143. // UIView* headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth,height)];
  144. // UILabel* headerLabel = [[UILabel alloc]initWithFrame:CGRectMake(35,height-19,KScreenWidth-35,15)];
  145. // headerLabel.textColor = LCTextGray;
  146. // headerLabel.font = LCFont12;
  147. // if (section==0) {
  148. // headerLabel.text = @"流光花舞未打开时";
  149. // }else{
  150. // headerLabel.text = @"流光花舞打开时";
  151. // }
  152. // [headerView addSubview:headerLabel];
  153. // return headerView;
  154. //}
  155. - (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
  156. if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender == 2&&![LCSaveData getWhiteVersion]) {
  157. if (section == 0||section==1) {
  158. UIView* footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 51)];
  159. UILabel* txtLabel = [[UILabel alloc]initWithFrame:CGRectMake(14, 0, KScreenWidth-28, 40)];
  160. txtLabel.font = [UIFont systemFontOfSize:12];
  161. txtLabel.textColor = LZA3AABEColor;
  162. txtLabel.numberOfLines = 0;
  163. if (section==1 && self.youpaipnotiFlag==NO) {
  164. txtLabel.text = @"你已在系统中关闭相语欢颜的通知。如需打开,点击上方开关跳转到设置打开“允许通知”";
  165. }else if(section == 1 && self.youpaipnotiFlag == YES){
  166. txtLabel.text = @"您已在系统设置中开启了相语欢颜的通知,如需关闭,请在系统设置-通知中,重新设置消息提醒权限。”";
  167. }
  168. if (section == 0) {
  169. txtLabel.text =@"开启后,相语欢颜将用大数据为您匹配有缘人,牵线成功会发送缘分消息,关闭后,将不会收到缘分牵线。";
  170. }
  171. [footView addSubview:txtLabel];
  172. return footView;
  173. }else{
  174. return nil;
  175. }
  176. }else{
  177. if (section == 0) {
  178. UIView* footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 51)];
  179. UILabel* txtLabel = [[UILabel alloc]initWithFrame:CGRectMake(14, 0, KScreenWidth-28, 40)];
  180. txtLabel.font = [UIFont systemFontOfSize:12];
  181. txtLabel.textColor = LZA3AABEColor;
  182. txtLabel.numberOfLines = 0;
  183. if (section==0 && self.youpaipnotiFlag==NO) {
  184. txtLabel.text = @"你已在系统中关闭相语欢颜的通知。如需打开,点击上方开关跳转到设置打开“允许通知”";
  185. }else if(section == 0 && self.youpaipnotiFlag == YES){
  186. txtLabel.text = @"您已在系统设置中开启了相语欢颜的通知,如需关闭,请在系统设置-通知中,重新设置消息提醒权限。”";
  187. }
  188. [footView addSubview:txtLabel];
  189. return footView;
  190. }else{
  191. return nil;
  192. }
  193. }
  194. }
  195. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  196. return 45;
  197. }
  198. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  199. YOUPAILCCommonSwitchCell * cell = [[YOUPAILCCommonSwitchCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"commonSwitchCell"];
  200. if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender == 2&&![LCSaveData getWhiteVersion]) {
  201. if (indexPath.section==0) {
  202. cell.youpaiprightBtn.hidden = YES;
  203. cell.youpaipcommonSwitch.hidden = NO;
  204. cell.youpaipcommonSwitch.tag = indexPath.row;
  205. cell.youpaipheadLabel.text = @"缘分牵线";
  206. cell.youpaipheadLabel.font = [UIFont systemFontOfSize:15];
  207. if (self.fate_match) {
  208. cell.youpaipcommonSwitch.selected = YES;
  209. }else{
  210. cell.youpaipcommonSwitch.selected = NO;
  211. }
  212. [cell.youpaipcommonSwitch addTarget:self action:@selector(youpaifopenFateSwitchValueChange:) forControlEvents:UIControlEventTouchUpInside];
  213. return cell;
  214. }else if (indexPath.section==1) {
  215. // cell.youpaipheadLabel.text = @"新消息通知";
  216. // cell.youpaipbaseView.layer.cornerRadius = 8;
  217. // cell.youpaipbaseView.layer.masksToBounds = YES;
  218. // cell.youpaipline.hidden = YES;
  219. // cell.youpaiprightBtn.hidden = NO;
  220. // cell.youpaipheadLabel.font = [UIFont systemFontOfSize:14];
  221. // cell.youpaipcommonSwitch.hidden = YES;
  222. cell.youpaiprightBtn.hidden = YES;
  223. cell.youpaipcommonSwitch.hidden = NO;
  224. cell.youpaipcommonSwitch.tag = indexPath.row;
  225. cell.youpaipheadLabel.text = @"新消息通知";
  226. cell.youpaipheadLabel.font = [UIFont systemFontOfSize:15];
  227. if (self.youpaipnotiFlag) {
  228. cell.youpaipcommonSwitch.selected = YES;
  229. // cell.youpaipcanSwitch = NO;
  230. //
  231. // [cell.youpaiprightBtn setTitle:@"已开启" forState:UIControlStateNormal];
  232. // [cell.youpaiprightBtn setTitleColor:HexColorFromRGB(0x9F9DA5) forState:UIControlStateNormal];
  233. }else{
  234. // cell.youpaipcanSwitch = YES;
  235. cell.youpaipcommonSwitch.selected = NO;
  236. // [cell.youpaiprightBtn setTitle:@"去开启" forState:UIControlStateNormal];
  237. // [cell.youpaiprightBtn setTitleColor:HexColorFromRGB(0xF4003F) forState:UIControlStateNormal];
  238. }
  239. [cell.youpaipcommonSwitch addTarget:self action:@selector(youpaifopenNotiSwitchValueChange:) forControlEvents:UIControlEventTouchUpInside];
  240. return cell;
  241. }
  242. else if (indexPath.section==2){
  243. cell.youpaiprightBtn.hidden = YES;
  244. cell.youpaipcommonSwitch.hidden = NO;
  245. cell.youpaipcommonSwitch.tag = indexPath.row;
  246. if (indexPath.row==0) {
  247. cell.youpaipheadLabel.text = @"声音";
  248. cell.youpaipheadLabel.font = [UIFont systemFontOfSize:15];
  249. cell.youpaipcommonSwitch.selected = [LCSaveData getIMMsgVoice];
  250. [cell.youpaipcommonSwitch addTarget:self action:@selector(youpaifvoiceSwitchValueChange:) forControlEvents:UIControlEventTouchUpInside];
  251. // [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:cell.youpaipbaseView size:CGSizeMake(8,8)];
  252. }else{
  253. cell.youpaipheadLabel.text = @"振动";
  254. cell.youpaipheadLabel.font = [UIFont systemFontOfSize:15];
  255. cell.youpaipcommonSwitch.selected = [LCSaveData getIMMsgShake];
  256. [cell.youpaipcommonSwitch addTarget:self action:@selector(youpaifshakeSwitchValueChange:) forControlEvents:UIControlEventTouchUpInside];
  257. cell.youpaipline.hidden = YES;
  258. // [LCTools clipCorner:UIRectCornerBottomLeft|UIRectCornerBottomRight View:cell.youpaipbaseView size:CGSizeMake(8,8)];
  259. }
  260. }
  261. return cell;
  262. }else{
  263. if (indexPath.section==0) {
  264. // cell.youpaipheadLabel.text = @"新消息通知";
  265. // cell.youpaipbaseView.layer.cornerRadius = 8;
  266. // cell.youpaipbaseView.layer.masksToBounds = YES;
  267. // cell.youpaipline.hidden = YES;
  268. // cell.youpaiprightBtn.hidden = NO;
  269. // cell.youpaipheadLabel.font = [UIFont systemFontOfSize:14];
  270. // cell.youpaipcommonSwitch.hidden = YES;
  271. cell.youpaiprightBtn.hidden = YES;
  272. cell.youpaipcommonSwitch.hidden = NO;
  273. cell.youpaipcommonSwitch.tag = indexPath.row;
  274. cell.youpaipheadLabel.text = @"新消息通知";
  275. cell.youpaipheadLabel.font = [UIFont systemFontOfSize:15];
  276. if (self.youpaipnotiFlag) {
  277. cell.youpaipcommonSwitch.selected = YES;
  278. // cell.youpaipcanSwitch = NO;
  279. //
  280. // [cell.youpaiprightBtn setTitle:@"已开启" forState:UIControlStateNormal];
  281. // [cell.youpaiprightBtn setTitleColor:HexColorFromRGB(0x9F9DA5) forState:UIControlStateNormal];
  282. }else{
  283. // cell.youpaipcanSwitch = YES;
  284. cell.youpaipcommonSwitch.selected = NO;
  285. // [cell.youpaiprightBtn setTitle:@"去开启" forState:UIControlStateNormal];
  286. // [cell.youpaiprightBtn setTitleColor:HexColorFromRGB(0xF4003F) forState:UIControlStateNormal];
  287. }
  288. [cell.youpaipcommonSwitch addTarget:self action:@selector(youpaifopenNotiSwitchValueChange:) forControlEvents:UIControlEventTouchUpInside];
  289. return cell;
  290. }
  291. else if (indexPath.section==1){
  292. cell.youpaiprightBtn.hidden = YES;
  293. cell.youpaipcommonSwitch.hidden = NO;
  294. cell.youpaipcommonSwitch.tag = indexPath.row;
  295. if (indexPath.row==0) {
  296. cell.youpaipheadLabel.text = @"声音";
  297. cell.youpaipheadLabel.font = [UIFont systemFontOfSize:15];
  298. cell.youpaipcommonSwitch.selected = [LCSaveData getIMMsgVoice];
  299. [cell.youpaipcommonSwitch addTarget:self action:@selector(youpaifvoiceSwitchValueChange:) forControlEvents:UIControlEventTouchUpInside];
  300. // [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:cell.youpaipbaseView size:CGSizeMake(8,8)];
  301. }else{
  302. cell.youpaipheadLabel.text = @"振动";
  303. cell.youpaipheadLabel.font = [UIFont systemFontOfSize:15];
  304. cell.youpaipcommonSwitch.selected = [LCSaveData getIMMsgShake];
  305. [cell.youpaipcommonSwitch addTarget:self action:@selector(youpaifshakeSwitchValueChange:) forControlEvents:UIControlEventTouchUpInside];
  306. cell.youpaipline.hidden = YES;
  307. // [LCTools clipCorner:UIRectCornerBottomLeft|UIRectCornerBottomRight View:cell.youpaipbaseView size:CGSizeMake(8,8)];
  308. }
  309. }
  310. return cell;
  311. }
  312. return nil;
  313. }
  314. -(void)openBtnClick{
  315. }
  316. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  317. if (indexPath.section==1) {
  318. if (self.youpaipnotiFlag == NO) {
  319. NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
  320. if ([[UIApplication sharedApplication] canOpenURL:url]) {
  321. [[UIApplication sharedApplication] openURL:url];
  322. }
  323. }
  324. }
  325. }
  326. - (void)youpaifopenNotiSwitchValueChange:(UIButton*)switchView{
  327. NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
  328. if ([[UIApplication sharedApplication] canOpenURL:url]) {
  329. [[UIApplication sharedApplication] openURL:url];
  330. }
  331. }
  332. - (void)youpaifvoiceSwitchValueChange:(UIButton*)switchView{
  333. switchView.selected = !switchView.selected;
  334. if (switchView.selected==YES) {
  335. [LCSaveData saveIMMsgVoice:YES];
  336. }else{
  337. [LCSaveData saveIMMsgVoice:NO];
  338. }
  339. }
  340. - (void)youpaifshakeSwitchValueChange:(UIButton*)switchView{
  341. switchView.selected = !switchView.selected;
  342. if (switchView.selected==YES) {
  343. [LCSaveData saveIMMsgShake:YES];
  344. }else{
  345. [LCSaveData saveIMMsgShake:NO];
  346. }
  347. }
  348. -(void)getFateMatch{
  349. [LCHttpHelper requestWithURLString:Mine_getFateMatch parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  350. NSDictionary* dict = (NSDictionary*)responseObject;
  351. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  352. if (code==0) {//成功
  353. // 缘分牵线 1开启 0关闭
  354. self.fate_match =[dict[@"data"][@"fate_match"] intValue];
  355. NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:0];
  356. [self.youpaiptableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationNone];
  357. }
  358. } failure:^(NSError *error) {
  359. }];
  360. }
  361. -(void)youpaifopenFateSwitchValueChange:(UIButton*)sender{
  362. sender.selected = !sender.selected;
  363. NSInteger fateStatus = sender.selected ==YES? 1:0;
  364. [LCHttpHelper requestWithURLString:Mine_setFateMatch parameters:@{@"fate_match":@(fateStatus)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  365. NSDictionary* dict = (NSDictionary*)responseObject;
  366. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  367. if (code==0) {//成功
  368. // 缘分牵线 1开启 0关闭
  369. self.fate_match = fateStatus;
  370. NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:0];
  371. [self.youpaiptableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationNone];
  372. }
  373. } failure:^(NSError *error) {
  374. }];
  375. }
  376. @end