YXAlertView.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. //
  2. // YXAlertView.m
  3. // Temperature
  4. //
  5. // Created by TC on 2025/4/25.
  6. //
  7. #import "YXAlertView.h"
  8. #import <WebKit/WebKit.h>
  9. @interface YXAlertView()<WKNavigationDelegate>
  10. @property (weak, nonatomic) UIView *contentView;
  11. @property (nonatomic, strong) WKWebView *webView;
  12. @property (nonatomic, strong) UILabel *textlabel;
  13. @end
  14. @implementation YXAlertView
  15. - (id)initWithFrame:(CGRect)frame
  16. {
  17. if (self = [super initWithFrame:frame])
  18. {
  19. // self.requestURL = @"https://app.yongxulvjian.com/#/PrivacyPolicy";
  20. [self createCoverView];
  21. [self createContentView];
  22. }
  23. return self;
  24. }
  25. -(void)createCoverView
  26. {
  27. UIView *coverView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  28. coverView.backgroundColor = [UIColor blackColor];
  29. coverView.alpha = 0.3;
  30. [self addSubview:coverView];
  31. }
  32. -(void)createContentView
  33. {
  34. UIView *contentView = [[UIView alloc]init];
  35. contentView.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
  36. [self addSubview:contentView];
  37. self.contentView = contentView;
  38. [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.centerX.equalTo(@0);
  40. make.centerY.equalTo(@0);
  41. make.width.equalTo(@(SCREEN_WIDTH - 80));
  42. make.height.equalTo(@(350));
  43. }];
  44. contentView.layer.cornerRadius = 10;
  45. UILabel *titleLabel = [[UILabel alloc]init];
  46. titleLabel.text = @"个人信息隐私保护政策";
  47. titleLabel.textColor = [UIColor colorWithHexString:@"#1F1F1F"];
  48. titleLabel.font = [UIFont boldSystemFontOfSize:18];
  49. titleLabel.textAlignment = NSTextAlignmentCenter;
  50. [contentView addSubview:titleLabel];
  51. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.top.equalTo(@30);
  53. make.centerX.equalTo(contentView.mas_centerX);
  54. make.height.equalTo(@30);
  55. make.width.equalTo(@260);
  56. }];
  57. WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
  58. config.userContentController = [[WKUserContentController alloc] init];
  59. config.allowsInlineMediaPlayback = YES;
  60. WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:config];
  61. webView.navigationDelegate = self;
  62. webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  63. [contentView addSubview:webView];
  64. [webView mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.top.equalTo(titleLabel.mas_bottom);
  66. make.left.equalTo(@7);
  67. make.right.equalTo(@-7);
  68. make.bottom.equalTo(@-80);
  69. }];
  70. self.webView = webView;
  71. // [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.requestURL]]];
  72. NSString* htmlPath = [[NSBundle mainBundle] pathForResource:@"YXAlertText" ofType:@"html"];
  73. NSString* appHtml = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];
  74. NSURL *baseURL = [NSURL fileURLWithPath:htmlPath];
  75. [self.webView loadHTMLString:appHtml baseURL:baseURL];
  76. // UILabel *textLabel = [[UILabel alloc]init];
  77. // textLabel.text = @"欢迎使用永续绿建五恒 APP,我们非常重视您的隐私保护和个人信息保护,使用本软件的过程中我们会严格按照法律规定收集存储和使用您的个人信息,未经您的同意我们不会向第三方提供您的任何信息,您可以阅读《用户协议》和《隐私政策》全文了解详细信息。如您同意,请点击“同意”开始接受我们的服务。";
  78. // textLabel.textColor = [UIColor colorWithHexString:@"#1F1F1F"];
  79. // textLabel.font = [UIFont systemFontOfSize:15];
  80. // textLabel.textAlignment = NSTextAlignmentJustified;
  81. // textLabel.numberOfLines = 0;
  82. // [contentView addSubview:textLabel];
  83. // [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  84. // make.top.equalTo(titleLabel.mas_bottom);
  85. // make.left.equalTo(@30);
  86. // make.right.equalTo(@-30);
  87. // make.bottom.equalTo(@-80);
  88. // }];
  89. UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  90. [rightBtn setTitle:@"不同意" forState:UIControlStateNormal];
  91. [rightBtn addTarget:self action:@selector(rightBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  92. [rightBtn setTitleColor:[UIColor colorWithHexString:@"#585D66"] forState:UIControlStateNormal];
  93. rightBtn.titleLabel.font = [UIFont systemFontOfSize:16];
  94. rightBtn.backgroundColor = [UIColor colorWithHexString:@"#F2F5FA"];
  95. [contentView addSubview:rightBtn];
  96. [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.top.equalTo(webView.mas_bottom).offset(20);
  98. make.left.equalTo(@40);
  99. make.height.equalTo(@40);
  100. make.width.equalTo(@100);
  101. }];
  102. rightBtn.layer.cornerRadius = 20;
  103. UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  104. [sureBtn setTitle:@"同意" forState:UIControlStateNormal];
  105. [sureBtn addTarget:self action:@selector(sureBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  106. [sureBtn setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
  107. sureBtn.titleLabel.font = [UIFont systemFontOfSize:16];
  108. sureBtn.backgroundColor = [UIColor colorWithHexString:@"#267AFF"];
  109. [contentView addSubview:sureBtn];
  110. [sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  111. make.top.equalTo(webView.mas_bottom).offset(20);
  112. make.right.equalTo(@-40);
  113. make.height.equalTo(@40);
  114. make.width.equalTo(@100);
  115. }];
  116. sureBtn.layer.cornerRadius = 20;
  117. }
  118. -(void)rightBtnAction:(UIButton *)btn
  119. {
  120. if (self.cancleBtnClick) {
  121. self.cancleBtnClick(self);
  122. }
  123. exit(0);
  124. }
  125. -(void)sureBtnAction:(UIButton *)btn
  126. {
  127. if (self.sureBtnClick) {
  128. self.sureBtnClick(self);
  129. }
  130. }
  131. #pragma mark - WKNavigationDelegate
  132. - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
  133. NSURL *url = navigationAction.request.URL;
  134. NSString *urlString = [url absoluteString];
  135. if ([urlString hasPrefix:@"https://app.yongxulvjian.com"]) {
  136. if (self.contentClick) {
  137. self.contentClick(self, urlString);
  138. }
  139. decisionHandler(WKNavigationActionPolicyCancel);
  140. }else{
  141. decisionHandler(WKNavigationActionPolicyAllow);
  142. }
  143. // // 获取请求的 URL
  144. // NSURL *url = navigationAction.request.URL;
  145. // NSString *urlString = [url absoluteString];
  146. //
  147. // // 检查 URL 是否需要被拦截或修改
  148. // if ([urlString hasPrefix:@"http://example.com/somepath"]) {
  149. // // 处理内部跳转或修改 URL
  150. // NSURL *newURL = [NSURL URLWithString:@"https://newexample.com"]; // 示例:修改 URL
  151. // NSURLRequest *newRequest = [NSURLRequest requestWithURL:newURL];
  152. // [webView loadRequest:newRequest];
  153. // decisionHandler(WKNavigationActionPolicyCancel); // 取消原始请求,加载新请求
  154. // } else {
  155. // // 允许其他 URL 正常加载
  156. // decisionHandler(WKNavigationActionPolicyAllow);
  157. // }
  158. }
  159. /*
  160. // Only override drawRect: if you perform custom drawing.
  161. // An empty implementation adversely affects performance during animation.
  162. - (void)drawRect:(CGRect)rect {
  163. // Drawing code
  164. }
  165. */
  166. @end