YBPrivateVC.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //
  2. // YBPrivateVC.m
  3. // YBVideo
  4. //
  5. // Created by YB007 on 2020/6/29.
  6. // Copyright © 2020 cat. All rights reserved.
  7. //
  8. #import "YBPrivateVC.h"
  9. #import "GuideViewController.h"
  10. #import <YYText/YYLabel.h>
  11. #import <YYText/NSAttributedString+YYText.h>
  12. @interface YBPrivateVC ()
  13. @property(nonatomic,strong)UIButton *agreeBtn;
  14. @property(nonatomic,strong)UIButton *unagreeBtn;
  15. @property(nonatomic,strong)YYLabel *contentL;
  16. @end
  17. @implementation YBPrivateVC
  18. - (void)viewWillAppear:(BOOL)animated {
  19. [super viewWillAppear:animated];
  20. [self pullData];
  21. }
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. AFNetworkReachabilityManager *netManager = [AFNetworkReachabilityManager sharedManager];
  25. [netManager startMonitoring];
  26. [netManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status){
  27. if (status == AFNetworkReachabilityStatusNotReachable){
  28. [self pullData];
  29. }else if (status == AFNetworkReachabilityStatusUnknown || status == AFNetworkReachabilityStatusNotReachable){
  30. NSLog(@"nonetwork-------");
  31. [self pullData];
  32. }else if ((status == AFNetworkReachabilityStatusReachableViaWWAN)||(status == AFNetworkReachabilityStatusReachableViaWiFi)){
  33. [self pullData];
  34. NSLog(@"wifi-------");
  35. }
  36. }];
  37. self.leftBtn.hidden = YES;
  38. self.agreeBtn = [self createBtn:YZMsg(@"同意") bgColor:Pink_Cor];
  39. self.unagreeBtn = [self createBtn:YZMsg(@"暂不使用") bgColor:RGB_COLOR(@"#ffffff", 0.1)];
  40. [_agreeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.bottom.equalTo(self.view.mas_bottom).offset(-36-ShowDiff);
  42. make.width.equalTo(self.view.mas_width).multipliedBy(0.4);
  43. make.height.mas_equalTo(35);
  44. make.centerX.equalTo(self.view.mas_centerX).multipliedBy(1.5);
  45. }];
  46. [_unagreeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.width.height.centerY.equalTo(_agreeBtn);
  48. make.centerX.equalTo(self.view.mas_centerX).multipliedBy(0.5);
  49. }];
  50. _contentL = [[YYLabel alloc]init];
  51. _contentL.textColor = RGB_COLOR(@"#ffffff", 1);
  52. _contentL.font = SYS_Font(15);
  53. _contentL.numberOfLines = 0;
  54. _contentL.preferredMaxLayoutWidth = _window_width*0.9;
  55. [self.view addSubview:_contentL];
  56. [_contentL mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.width.equalTo(self.view.mas_width).multipliedBy(0.9);
  58. make.centerX.equalTo(self.view.mas_centerX);
  59. make.top.equalTo(self.naviView.mas_bottom).offset(30);
  60. make.bottom.lessThanOrEqualTo(_agreeBtn.mas_top).offset(-10);
  61. }];
  62. if (_hideBottom) {
  63. self.leftBtn.hidden = NO;
  64. _agreeBtn.hidden = _unagreeBtn.hidden = YES;
  65. }
  66. }
  67. -(UIButton *)createBtn:(NSString *)title bgColor:(UIColor *)bgColor{
  68. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  69. btn.titleLabel.font = SYS_Font(15);
  70. [btn setTitleColor:RGB_COLOR(@"#ffffff", 1) forState:0];
  71. [btn setTitle:title forState:0];
  72. btn.backgroundColor = bgColor;
  73. btn.layer.cornerRadius = 5;
  74. btn.layer.masksToBounds = YES;
  75. [btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
  76. [self.view addSubview:btn];
  77. return btn;
  78. }
  79. -(void)clickBtn:(UIButton *)sender {
  80. if (sender == _unagreeBtn) {
  81. dispatch_async(dispatch_get_main_queue(), ^{
  82. //不同意条款主动结束程序
  83. //运行时不必关心这个函数;
  84. abort();
  85. });
  86. }
  87. if (sender == _agreeBtn) {
  88. [PublicObj resetVC:[[GuideViewController alloc] init]];
  89. }
  90. }
  91. -(void)pullData {
  92. YBWeakSelf;
  93. [YBNetworking postWithUrl:@"Home.getLogin" Dic:nil Suc:^(int code, id info, NSString *msg) {
  94. if (code == 0) {
  95. NSDictionary *infoDic = [info firstObject];
  96. NSDictionary *alertDic = [infoDic valueForKey:@"login_alert"];
  97. [weakSelf setupDate:alertDic];
  98. }
  99. } Fail:^(id fail) {
  100. }];
  101. }
  102. -(void)setupDate:(NSDictionary *)dataDic {
  103. self.titleL.text = minstr([dataDic valueForKey:@"title"]);
  104. if (_hideBottom) {
  105. self.titleL.text = YZMsg(@"隐私政策");
  106. }
  107. _contentL.text = [dataDic valueForKey:@"content"];
  108. NSArray *ppA = [NSArray arrayWithArray:[dataDic valueForKey:@"message"]];
  109. NSMutableAttributedString *textAtt = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@",_contentL.text]];
  110. [textAtt addAttribute:NSForegroundColorAttributeName value:RGB_COLOR(@"#ffffff", 1) range:textAtt.yy_rangeOfAll];
  111. [textAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:textAtt.yy_rangeOfAll];
  112. for (int i=0; i<ppA.count; i++) {
  113. NSDictionary *subDic = ppA[i];
  114. NSRange clickRange = [[textAtt string]rangeOfString:minstr([subDic valueForKey:@"title"])];
  115. [textAtt yy_setTextHighlightRange:clickRange color:Pink_Cor backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
  116. NSLog(@"协议");
  117. if ([PublicObj checkNull:minstr([subDic valueForKey:@"url"])]) {
  118. [MBProgressHUD showError:YZMsg(@"链接不存在")];
  119. return;
  120. }
  121. PubH5 *h5vc = [[PubH5 alloc]init];
  122. h5vc.url = minstr([subDic valueForKey:@"url"]);;
  123. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:h5vc animated:YES];
  124. }];
  125. }
  126. textAtt.yy_lineSpacing = 5;
  127. _contentL.attributedText = textAtt;
  128. }
  129. /*
  130. #pragma mark - Navigation
  131. // In a storyboard-based application, you will often want to do a little preparation before navigation
  132. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  133. // Get the new view controller using [segue destinationViewController].
  134. // Pass the selected object to the new view controller.
  135. }
  136. */
  137. @end